ModalPopupExtender OK Button click event not firing?

后端 未结 8 1426
旧巷少年郎
旧巷少年郎 2020-12-14 00:04

I have a Button inside an UpdatePanel. The button is being used as the OK button for a ModalPopupExtender. For some reason, the button click event is not firing. Any idea

相关标签:
8条回答
  • 2020-12-14 00:42

    It could also be that the button needs to have CausesValidation="false". That worked for me.

    0 讨论(0)
  • 2020-12-14 00:42

    I was just searching for a solution for this :)

    it appears that you can't have OkControlID assign to a control if you want to that control fires an event, just removing this property I got everything working again.

    my code (working):

    <asp:Panel ID="pnlResetPanelsView" CssClass="modalPopup" runat="server" Style="display:none;">
        <h2>
            Warning</h2>
        <p>
            Do you really want to reset the panels to the default view?</p>
        <div style="text-align: center;">
            <asp:Button ID="btnResetPanelsViewOK" Width="60" runat="server" Text="Yes" 
                CssClass="buttonSuperOfficeLayout" OnClick="btnResetPanelsViewOK_Click" />&nbsp;
            <asp:Button ID="btnResetPanelsViewCancel" Width="60" runat="server" Text="No" CssClass="buttonSuperOfficeLayout" />
        </div>
    </asp:Panel>
    <ajax:ModalPopupExtender ID="mpeResetPanelsView" runat="server" TargetControlID="btnResetView"
        PopupControlID="pnlResetPanelsView" BackgroundCssClass="modalBackground" DropShadow="true"
        CancelControlID="btnResetPanelsViewCancel" />
    
    0 讨论(0)
  • 2020-12-14 00:48

    Put into the Button-Control the Attribute "UseSubmitBehavior=false".

    0 讨论(0)
  • 2020-12-14 00:48

    I often use a blank label as the TargetControlID. ex. <asp:Label ID="lblghost" runat="server" Text="" />

    I've seen two things that cause the click event not fire:
    1. you have to remove the OKControlID (as others have mentioned)
    2. If you are using field validators you should add CausesValidation="false" on the button.

    Both scenarios behaved the same way for me.

    0 讨论(0)
  • 2020-12-14 00:54

    Aspx

    <ajax:ModalPopupExtender runat="server" ID="modalPop" 
                PopupControlID="pnlpopup" 
                TargetControlID="btnGo"
                  BackgroundCssClass="modalBackground"
                 DropShadow="true"
                 CancelControlID="btnCancel" X="470" Y="300"   />
    
    
    //Codebehind    
    protected void OkButton_Clicked(object sender, EventArgs e)
        {
    
            modalPop.Hide();
            //Do something in codebehind
        }
    

    And don't set the OK button as OkControlID.

    0 讨论(0)
  • 2020-12-14 00:59

    None of the previous answers worked for me. I called the postback of the button on the OnOkScript event.

    <div>
        <cc1:ModalPopupExtender PopupControlID="Panel1" 
             ID="ModalPopupExtender1"
             runat="server" TargetControlID="LinkButton1" OkControlID="Ok" 
             OnOkScript="__doPostBack('Ok','')">
        </cc1:ModalPopupExtender>
    
        <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton> 
    </div>        
    
    
    <asp:Panel ID="Panel1" runat="server">
        <asp:Button ID="Ok" runat="server" Text="Ok" onclick="Ok_Click" />            
    </asp:Panel>   
    
    0 讨论(0)
提交回复
热议问题