Note that there are some explanatory texts on larger screens.

plurals
  1. POModalPopupExtender not displaying on button postback within updatepanel
    text
    copied!<p>I know this flavor of question has been asked multiple times, but I've spent hours sifting through answers that don't match or don't work and I'm at wits end.</p> <p>Background: I have a situation where I want to evaluate a record to make sure it fits a specific set of criteria. If it fits the criteria, raise an alert message for confirmation from the user. I do not want to raise the popup unless the criteria matches.</p> <p><strong>Pseudocode of what I want to accomplish:</strong></p> <ul> <li>User enters information in multiple fields </li> <li>User clicks "Save" (cmdUpdate)</li> <li>within the "Save" click function it checks to see if the same record already exists in the database (e.g. this is a duplicate). </li> <li>If it's not a duplicate continue with the save function </li> <li>If it's a duplicate prompt the user for confirmation to save the dup.</li> </ul> <p>I can't get the popup to display before/after the postback. I've tried a hack workaround of setting a session value to maintain the state. The value tests positive in the prerender and does call the modalpopupextender.show but it never fires successfully to the screen. I'm not opposed to switching to a javascript solution if someone has a better method but I have to do the check for duplicates in the asp.net code behind.</p> <p><strong>Markup:</strong></p> <pre><code>&lt;asp:UpdatePanel ID="upMainContent" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False" &gt; &lt;ContentTemplate&gt; &lt;asp:Label ID="lblDummy" runat="server" EnableViewState="false" Style="display: none;" /&gt; &lt;asp:Panel ID="pnlConfirmation" runat="server" Width="400px" Style="display: none;" CssClass="ModalPopupFront"&gt; &lt;div ID="Div1" runat="server" class="PopupHeader" style="width:400px;"&gt;&amp;nbsp;&amp;nbsp;Duplicate Record&lt;/div&gt; &lt;br /&gt; &lt;asp:Label ID="lblConfirmationMessage" runat="server" Text="This record has already exists.&lt;br/&gt; Are you sure you want to save a duplicate entry?"&gt;&lt;/asp:Label&gt;&lt;br /&gt; &lt;br /&gt; &lt;div style="text-align:right;"&gt; &lt;asp:Button ID="btnSaveAnyway" runat="server" Text="Save" OnClick="btnSaveAnyway_Click" /&gt; &lt;asp:Button ID="btnCancelSave" runat="server" Text="Cancel" OnClick="btnCancelSave_Click" /&gt; &lt;/div&gt; &lt;/asp:Panel&gt; &lt;ajax:ModalPopupExtender ID="mpeSaveConfirmation" runat="server" Enabled="False" TargetControlID="lblDummy" PopupControlID="pnlConfirmation" BackgroundCssClass="modalBackground" DropShadow="true" CancelControlID="btnCancelSave" RepositionMode="RepositionOnWindowResizeAndScroll" PopupDragHandleControlID="pnlConfirmation" Drag="true"&gt; &lt;/ajax:ModalPopupExtender&gt; &lt;!-- all the input fields/misc content --&gt; &lt;asp:Button id="cmdUpdate" runat="server" CausesValidation="true" OnClick="cmdUpdate_Click" Text="Save" ValidationGroup="vg1" ToolTip="Save the current record" TabIndex="102" /&gt; &lt;/ContentTemplate&gt; &lt;Triggers&gt; &lt;asp:AsyncPostBackTrigger ControlID="ddlStateId" EventName="SelectedIndexChanged" /&gt; &lt;asp:AsyncPostBackTrigger ControlID="ddlCountyId" EventName="SelectedIndexChanged" /&gt; &lt;/Triggers&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p><strong>Code behind:</strong></p> <pre><code> Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender '... If GetSessionValue("HackWorkaround") Then mpeSaveConfirmation.Enabled = True mpeSaveConfirmation.Show() End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load '... If not Page.IsPostBack Then SetSessionValue("HackWorkaround", False) End if '... End Sub Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) If tbOpTill.NewRecordIdenticalToLast() And tbOpRecord.NewRecordIdenticalToLast() Then SetSessionValue("HackWorkaround", True) Else SetSessionValue("HackWorkaround", False) SetSessionValue("LastOpRecordIDSaved", tbOpRecord.OpRecordId) Dim isEdit As Boolean = ResetOpRecord("Till", tbOpTill) SmartRedirect("Optill/oprecord_edit.aspx") End If End Sub Protected Sub btnSaveAnyway_Click(ByVal sender As Object, ByVal e As System.EventArgs) SetSessionValue("HackWorkaround", False) mpeSaveConfirmation.Enabled = False mpeSaveConfirmation.Hide() 'Duplicate record exists, but the customer wants to save anyway. DoSave() Dim isEdit As Boolean = ResetOpRecord("Till", tbOpTill) SmartRedirect("Optill/oprecord_edit.aspx") End Sub Protected Sub btnCancelSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) SetSessionValue("HackWorkaround", False) mpeSaveConfirmation.Enabled = False mpeSaveConfirmation.Hide() 'do nothing and return to the screen. End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload