0

I am having some very strange behaviour in IE with my .Net buttons.

I have a normal HTML button.

    <input type="submit" onclick="return Valadation()" value="Save profile" class="btn primary rounded" />

Which then calls some simple JavaScript

   if (txbEmail.length == 0) {
          $("[id$='txbEmail']").addClass("error");
          $("[id$='txbEmail']").focus().select();
          showMessage = true;
          displayMessage += "Email Address, "
    }
    else {
         $("[id$='txbEmail']").removeClass("error");
    }

    if (showMessage) {ShowStatus("warning", displayMessage);
    return false;
    }
    else {
   var saveButton = $('[id*="butSave"]');
   saveButton.focus();
   saveButton.click();

}

With the final result clicking a asp.net button

<asp:Button ID="butSave" runat="server" Style="display: none;" onclick="butSave_Click" />

This issue is that Ie just wont ever post the page back? works fine on FF, Chrome, just not IE

3
  • 3
    does it show any script error ? Commented Apr 6, 2011 at 11:40
  • You can't focus hidden element. Just remove the saveButton.focus(); line. Probably FF and Chrome graciously ignore this while IE crash with error, thus not getting to the line afterwards.. Commented Apr 6, 2011 at 11:52
  • Finally figured out what's happening. the blank input field is submitting the form before click event in IE, any ideas how to stop it? Commented Apr 6, 2011 at 13:38

2 Answers 2

3

If you need the ASP button to perform javascript validation, use the OnClientClick property:

<asp:Button ID="butSave" runat="server" Style="display: none;" onclientclick="return Valadation()" onclick="butSave_Click" />

Simply return false from your Valadation() method to stop the asp button from submitting.

Sign up to request clarification or add additional context in comments.

1 Comment

Tried this didn't work, but I did finally find the error within the jQuery forum. I have added an answer to fix this issue.
0

Turns out this is a known issues within jQuery and wont be fixed, but there is a very easy work around.

The script .click() will not work if the button in question has the type="submit" (only in IE wont this work IE7,IE8,IE9 all show this error).

But if you just change the button type to type="button" the .click() event works just fine.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.