[ACCEPTED]-ModalPopupExtender OK Button click event not firing?-modalpopupextender

Accepted answer
Score: 53

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

Score: 10

It appears that a button that is used as 6 the OK or CANCEL button for a ModalPopupExtender 5 cannot have a click event. I tested this 4 out by removing the

OkControlID="ModalOKButton"

from the ModalPopupExtender 3 tag, and the button click fires. I'll need 2 to figure out another way to send the data 1 to the server.

Score: 8

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

Score: 6

I was just searching for a solution for 4 this :)

it appears that you can't have OkControlID assign 3 to a control if you want to that control 2 fires an event, just removing this property 1 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" />
Score: 5

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

Score: 2

None of the previous answers worked for 2 me. I called the postback of the button 1 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>   
Score: 2

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

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

Both scenarios behaved the same 1 way for me.

Score: 1

I've found a way to validate a modalpopup 6 without a postback.

In the ModalPopupExtender 5 I set the OnOkScript to a function e.g ValidateBeforePostBack(), then 4 in the function I call Page_ClientValidate 3 for the validation group I want, do a check 2 and if it fails, keep the modalpopup showing. If 1 it passes, I call __doPostBack.

function ValidateBeforePostBack(){ 
     Page_ClientValidate('MyValidationGroupName'); 
     if (Page_IsValid) { __doPostBack('',''); } 
     else { $find('mpeBehaviourID').show(); } 
}

More Related questions