Matt
Matt

Reputation: 5660

How do I force a postback on an ASP.NET button inside a jQuery modal dialog (div)?

I have a modal dialog showing up and the user can make some changes and then click a 'Save' button. I need that to totally post back the whole page. What would you suggest? I just assumed the button would fire off regardless of the jQuery.

Upvotes: 1

Views: 12994

Answers (3)

sec0ndHand
sec0ndHand

Reputation: 429

The basics I use are:

  1. Create an ASP button on the page outside of the modal div

    <asp:Button ID="hiddenButton" runat="server" onclick="hiddenButton_Click" style="visibility:hidden" />`
    
  2. Assuming you have the Save button already in your modal div, call the button click event in JavaScript(this was taken from a jQuery dialog event):

    buttons: {
        Save: function () {
            $(this).dialog('close');
            $("#<%=hiddenButton.ClientID %>").click();
        }
    }
    

Upvotes: 2

yamspog
yamspog

Reputation: 18333

put an asp button on the page and hide it with css in the onclose event of the dialog window, call aspButton.click

<asp:button id="myButton" runat="server" OnClick="myButton_Click" style="visible:hidden;" />

...

$('#' + <%= myButton.ClientID %>).click();

Upvotes: 3

Matthew Jones
Matthew Jones

Reputation: 26190

You could force a post back from Javascript:

__doPostBack(id,'');

To do this directly from a control, like a button, use OnClientClick:

<asp:Button id="myButton" runat=server OnClientClick="__doPostBack(id,'');" />

Upvotes: 8

Related Questions