WhiteLime
WhiteLime

Reputation: 1

ModalPopupExtender bypassing OnClick

Hey so I am pretty new to asp.net, I am trying to create a website/form that takes in a bunch of data and do stuff with it. I have a submit button that invokes a submitButton_Click method, but I am also having the a modalpopup that presents a "please wait" updatepanel while I do the processing on the server end on the same event. The problem is that it seems like the modalpopup is working fine, but it is surpressing my submitButton_Click method call. What do I do?

Also, if it possiable to have a default method that is invoked when the updatepanel opens? I want the panel to be the same everytime it pops up despite that I update it with the last time.

<asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="submitButton_Click"
            CssClass="buttons"/>

<asp:ModalPopupExtender 
        ID="modalProgress" 
        runat="server" 
        OkControlID="btnOkay" 
        TargetControlID="submitButton" 
        PopupControlID="progessPanel"
        BackgroundCssClass="modalBackground">

</asp:ModalPopupExtender>

Upvotes: 0

Views: 3100

Answers (1)

James Johnson
James Johnson

Reputation: 46047

It doesn't bypass the click event; it just changes the client-side onclick to return false, which negates the postback. Honestly, I've always found this to be a pain in the butt. Forunately, there is a workaround:

<asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="submitButton_Click"                CssClass="buttons"/>
<!-- hidden button to satisfy the extender -->
<asp:Button ID="hiddenButton" runat="server" style="display:hidden" />

<asp:ModalPopupExtender 
        ID="modalProgress" 
        runat="server" 
        OkControlID="btnOkay" 
        TargetControlID="hiddenButton" 
        PopupControlID="progessPanel"
        BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>

By adding a hidden button you'll satisfy the requirements of the extender, and you can open the dialog in code-behind from the submit button's click event:

protected void submitButton_Click(object sender, EventArgs e)
{
    //display the modal dialog
    modalProgress.Show();
}

Upvotes: 2

Related Questions