【问题标题】:ModalPopupExtender not displaying on button postback within updatepanelModalPopupExtender 未显示在更新面板中的按钮回发上
【发布时间】:2011-07-31 17:57:21
【问题描述】:

我知道这种类型的问题已经被问过多次,但我花了好几个小时筛选不匹配或不起作用的答案,而我束手无策。

背景:我有一种情况,我想评估一条记录以确保它符合一组特定的标准。如果符合标准,请发出警报消息以供用户确认。除非条件匹配,否则我不想引发弹出窗口。

我想要完成的伪代码:

  • 用户在多个字段中输入信息
  • 用户点击“保存”(cmdUpdate)
  • 在“保存”单击功能中,它会检查是否已存在相同的记录 在数据库中(例如,这是重复的)。
  • 如果不是重复的,请继续使用保存功能
  • 如果是重复的,则提示用户确认保存副本。

我无法在回发之前/之后显示弹出窗口。我尝试了一种设置会话值以维护状态的破解解决方法。该值在预渲染中测试为正,并且确实调用了 modalpopupextender.show 但它从未成功触发到屏幕。如果有人有更好的方法,我不反对切换到 javascript 解决方案,但我必须检查 asp.net 后面代码中的重复项。

标记:

<asp:UpdatePanel ID="upMainContent" runat="server" UpdateMode="Conditional"  ChildrenAsTriggers="False" >
    <ContentTemplate>
    <asp:Label ID="lblDummy" runat="server" EnableViewState="false" Style="display: none;" />
    <asp:Panel ID="pnlConfirmation" runat="server" Width="400px" Style="display: none;" CssClass="ModalPopupFront">
        <div ID="Div1" runat="server" class="PopupHeader" style="width:400px;">&nbsp;&nbsp;Duplicate Record</div>
        <br />
        <asp:Label ID="lblConfirmationMessage" runat="server" Text="This record has already exists.<br/> Are you sure you want to save a duplicate entry?"></asp:Label><br />
        <br />
        <div style="text-align:right;">
        <asp:Button ID="btnSaveAnyway" runat="server" Text="Save" OnClick="btnSaveAnyway_Click" />
        <asp:Button ID="btnCancelSave" runat="server" Text="Cancel" OnClick="btnCancelSave_Click"  />
        </div>
    </asp:Panel>
    <ajax:ModalPopupExtender ID="mpeSaveConfirmation" runat="server" Enabled="False" 
        TargetControlID="lblDummy" PopupControlID="pnlConfirmation" 
        BackgroundCssClass="modalBackground" DropShadow="true" 
        CancelControlID="btnCancelSave"
        RepositionMode="RepositionOnWindowResizeAndScroll" PopupDragHandleControlID="pnlConfirmation" Drag="true">
    </ajax:ModalPopupExtender>


    <!-- all the input fields/misc content -->

     <asp:Button id="cmdUpdate" runat="server" CausesValidation="true" OnClick="cmdUpdate_Click" Text="Save" ValidationGroup="vg1"  ToolTip="Save the current record" TabIndex="102" />

    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlStateId" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="ddlCountyId" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel> 

背后的代码:

    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

【问题讨论】:

    标签: asp.net ajax vb.net .net-3.5 modalpopupextender


    【解决方案1】:

    您的问题在这里:

    <ajax:ModalPopupExtender ID="mpeSaveConfirmation" runat="server" Enabled="False"
    
    Protected Sub btnSaveAnyway_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        SetSessionValue("HackWorkaround", False)
        **mpeSaveConfirmation.Enabled = False**
        mpeSaveConfirmation.Hide()
    

    在后面的代码中实现。并相应地同步隐藏显示。我还可以在您使用 Style="display:none" 的某些地方的代码中看到。所以如果你想显示你需要使用 HtmlStyleWriter.Display,"block"。如果在这种情况下使用 Visible true false 它将不起作用。我的意思是说,无论你在哪里使用可见的真假,在代码隐藏中你都必须使用类似的。如果您使用样式,那么在代码隐藏中您必须使用相同的样式。

    【讨论】:

    • 删除设置 .Enabled true/false 的代码解决了这个问题。在这种情况下,我不明白该属性的用途,但它起作用了,所以我愿意放手。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    相关资源
    最近更新 更多