0

I have an asp:button with appropriate OnClick. I also have a jQuery UI dialog that opens when said button is clicked. I would like the OnClick function to be called when the user clicks "Yes" in the dialog. Even better would be if one codebehind function was called for "Yes" and another for "No." But for the life of me I can't figure out how.

Here's my current code:

$(function() {
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-confirm").dialog({
            autoOpen:false,
            resizable:false,
            height:175,
            width: 450,
            modal:true,
            buttons: {
                "Yes": function() {

                    $(this).dialog("close");
                },
                "No": function() {
                    $(this).dialog("close");
                }
            }

        });


    $(".navigation").click(function(e) {
        e.preventDefault();
        $("#dialog-confirm").dialog('open');

    });
});

and the button:

<asp:Button ID="testerE" class="navigation" runat="server" OnClick="JustATest" Text="Test me" />
ScottieB
  • 3,958
  • 6
  • 42
  • 60

1 Answers1

0

Why don't you put those buttons inside a div and use that as the html that is displayed in the modal dialog?

<div id="my-placeholder-for-dialog">
  Text goes here
  <asp:Button ID="testerE" class="navigation" runat="server" OnClick="JustATest" Text="Test me" />
</div>

Otherwise, you would need to call the __doPostBack function that is present on the page.

Khanzor
  • 4,830
  • 3
  • 25
  • 41
  • Still doesn't run the code behind when clicked in the dialog.

    You are navigating away from this banner-IPG, do you want to save any changes?

    – ScottieB Dec 29 '11 at 00:38
  • How does the rendered HTML appear? – Khanzor Dec 29 '11 at 00:46
  • Turns out I left out a vital step: http://stackoverflow.com/questions/757232/jquery-ui-dialog-with-asp-net-button-postback – ScottieB Dec 29 '11 at 00:53
  • It would be nice if I could write the jQuery such that if you click "yes" you do whatever the postback of the button was. I have three navigation buttons (forward, back, complement) so it'd be nice to write one .click in jQuery ('Save changes?') so that if the user clicks 'No' they continue with their original onclick, and if 'Yes' then do the Save_Changes function before doing the original onclick. – ScottieB Dec 29 '11 at 00:58