1

From a jQuery noob, any help is appreciated with this as I've wasted too much time already with a deadline fast approaching.

The lowdown - I have an asp.net form in an intranet engineering application that needs to pop up a jQuery dialog when the Submit button is pressed in certain circumstances.

In the "certain circumstances" the user needs to confirm a question and the form needs to continue with submission including executing the server-side code for the Submit button's Click event.

When the "certain circumstances" don't exist, the form needs to simply submit and execute the server-side code for the Submit button's Click event. (Same as above, but with no jQuery Dialog.)

The challenge seems to be:

  • When the dialog closes, the form submits but it is obviously *not* as if the original Submit button caused it since the only server-side code being executed is `Page_Load`. The `cmdSave_Click' (which is what I also need to execute) is not called.

Here is the dialog box definition. (On both button clicks I need to stick a value in a hidden field that the server-side cmdSave_Click method ultimately needs.)

var dlgTidPopup = $('#popupPnlTid').dialog({
    resizable: false,
    autoOpen: false,
    draggable: false,
    modal: true,
    closeOnEscape: false,
    title: 'Request for Target Identifier (TID)?',
    buttons: {
        "yes": function () {
            $('#txtTidYes').val("1");
            $('#userInputForm').unbind("submit").submit();
            $(this).dialog('close');
        },
        "no": function () {
            $('#txtTidYes').val("0");
            $('#userInputForm').unbind("submit").submit();
            $(this).dialog('close');
        }
    }
});

dlgTidPopup.parent().appendTo($('form:first'));

Here is the submission portion. The if statement determines the appearance of the dialog to satisfy the "is this that certain circumstance?" requirement.

$('#userInputForm').submit(function (event) {
    if ($('#hdnSituationIsTid').val() == "1") {
        event.preventDefault();
        $('#popupPnlTid').dialog("open");
    }
});

The submit button looks like:

<asp:ImageButton ID="ibtnSend" ImageUrl="../_common/Images/buttons/Send.gif"
  runat="server" OnCommand="cmdSave_Click" CommandName="Send" CssClass="majorButton"
  CausesValidation="false" />

The answer to this is probably so simple and I am just lacking in knowledge. Any guidance is greatly appreciated. (Also, do know that I've scoured SO and read many, many posts and have even modeled my code after many of them, but I haven't quite found a resolution to my specific question.)

rick schott
  • 21,012
  • 5
  • 52
  • 81
Monica
  • 55
  • 1
  • 11
  • 1
    I haven't tried `Command` with jQuery, but if the user selects 'yes', could you programmatically click the 'submit' button? `$('#<%=ibtnSend.ClientID %>').click();` – keyboardP Nov 22 '11 at 03:18
  • Thank you kP, I did try something like that, but because it _is_ the submit button that is invoking the dialog already, I continued to run into problems presented by having to submit (the button), then unbind the submit (during dialog), then _re_submit without then having to enact the scenario all over again. I'm thinking this circumstance is showing me that the most solid model when there is so much client-side activity is to get away from buttons that automatically submit so that the developer has a greater degree of control over the flow. So I'm playing with the solution below to see. – Monica Nov 22 '11 at 19:27

1 Answers1

1

See my answer on the question linked below, I use a hidden asp:button for the callback:

ASP.NET with jQuery popup dialog: how to post back on dialog closing

 function showjQueryUIDialogOkBtnCallback(buttonToClick, dialogSelector, buttonTxt, isModal, width, height) 
   {
       var buttonOpts = {};
       buttonOpts[buttonTxt] = function () {
           $("#" + buttonToClick).trigger('click');
       };

       buttonOpts['Cancel'] = function () {
           $(this).dialog("close");
           $(this).dialog('destroy'); 
       }

       $(dialogSelector).dialog({
           resizable: false,
           height: height,
           width: width,
           modal: isModal,
           open: function (type, data) {
               $(this).parent().appendTo("form"); //won't postback unless within the form tag
           },
           buttons: buttonOpts

       });

       $(dialogSelector).dialog('open');

    }
Community
  • 1
  • 1
rick schott
  • 21,012
  • 5
  • 52
  • 81
  • Thank you Rick, this is a very elegant script. I did happen to find your other post yesterday and had read through it but didn't see the correlation at the time. My guess is that the button that causes your dialog to open is not a submit button or there would be no need to trigger a hidden button to submit the form. I'm working with a submit button (image) right now, but I am going to change that and see if I can't get good results using your suggestion. Let you know! And thank you so much for the response. – Monica Nov 22 '11 at 17:39