1

I have a submit button on my asp.net form:

<asp:Button ID="btnSave" Text="Save" runat="server" Width="75px" Enabled="false"
            OnClick="btnSave_Click"/>

It renders as such in the html:

<input id="MainContent_btnSave" type="submit" style="width:75px;" value="Save" name="ctl00$MainContent$btnSave">

I'm using a jquery ui dialog that incorporates the Save button of the dialog, and when the user clicks the Save button in the dialog then I am trying to force the click event of the submit button (mentioned above), but I'm having no luck what-so-ever with it. I've tried the following, but every single one has failed to cause the form to submit:

function SaveDialog() {
  $("input[id$='_btnSave']").click();
  $("input[id$='_btnSave']").trigger('click');
  $('#<%=btnSave.ClientID %>').trigger('click');
  document.getElementById('<%=btnSave.ClientID %>').onclick();
}

I've verified that the SaveDialog() function is being called by placing alerts in it. I've also verified that my first selector in the function is actually finding the Save button.

The only thing I can guess at is the jquery ui dialog being modal is somehow stopping the submit event of the save button from being raised.

Any help or thoughts on this would be greatly appreciated. Thanks.

EDIT: This does work for submitting the form:

$(form:first").submit();

But I still need to figure out how to raise the submit click event!

2
  • What about document.getElementById('<%=btnSave.ClientID %>').click(); ? Or, if your code is in external JS file - direct document.getElementById('MainContent_btnSave').click(); (assumning that 'MainContent_btnSave' is indeed client-rendered ID of the button. Note use of click() instead of onclick() Jun 24, 2013 at 22:04
  • Good catch. I changed it to .click() but it's still not submitting. Something else is going on here that is interrupting the submit, I'm certain of it. I've looked in the various .js files being included, but I can't see anything that would be catching the click event and prematurely ending it.
    – Jagd
    Jun 24, 2013 at 22:17

1 Answer 1

2

It's the modal property of the jQuery UI dialog. Try setting it to false and you should be able to trigger the submit of the page then.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.