views:

17045

answers:

8

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 ideas? Am I missing something?

<asp:updatepanel id="UpdatePanel1" runat="server">
 <ContentTemplate>
        <cc1:ModalPopupExtender ID="ModalDialog" runat="server" 
            TargetControlID="OpenDialogLinkButton"
   PopupControlID="ModalDialogPanel" OkControlID="ModalOKButton"
   BackgroundCssClass="ModalBackground">
  </cc1:ModalPopupExtender>
  <asp:Panel ID="ModalDialogPanel" CssClass="ModalPopup" runat="server">
   ...
   <asp:Button ID="ModalOKButton" runat="server" Text="OK" 
                        onclick="ModalOKButton_Click" />
  </asp:Panel>
 </ContentTemplate>
</asp:updatepanel>
+3  A: 

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

OkControlID="ModalOKButton"

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

Kyle Trauberman
+2  A: 

You should take a look at Matt Berseth's site. He has a heap of stuff on the ModalPopupExtender and just the kinda thing your trying to do:

ModalPopupExtender articles:

http://mattberseth.com/blog/modalpopupextender/

Each article has a worked example with source code.

Kev
Good resource but doesn't answer the question.
John Nolan
Eh? It clearly did because the OP marked it as the answer.
Kev
Also I had exactly the same issue as OP and Berseth's techniques are the HOW-TO/pattern for this kinda behaviour using the modal popup extender. So please can I have my points back?
Kev
+1  A: 

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" />
balexandre
A: 

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>
John Nolan
If you remove OKControlID from your ModalPopupExtender, the button will postback like normal. In your event, you can call ModalPopupExtender.Hide() to hide the popup.
Kyle Trauberman
A: 

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

Johan Leino
+2  A: 

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.

Your's is the correct answer.
aceinthehole
A: 

I checked some version of AjaxControlToolkit and I think it's bug. after version 3.0.30512 we have this problem.

Amir
A: 

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

Stefan Weiss