click() not behaving like user click
Posted
by rpiontek
on Stack Overflow
See other posts from Stack Overflow
or by rpiontek
Published on 2010-03-15T20:45:10Z
Indexed on
2010/03/15
20:59 UTC
Read the original article
Hit count: 486
I have searched for a solution to this for the last several hours but to no avail. When I click on a button that has a return false in OnClientClick, no postback occurs to the server. When I use jquery to trigger the click function of the button, OnClientClick fires first, but regardless of the return value, a postback occurs. Here's a simple sample...
<form id="form1" runat="server">
<div>
<asp:Button ID="Button2" OnClientClick="$('#Button1').click();" runat="server" Text="Trigger" /><br />
<asp:Button ID="Button1" OnClick="Button1_Click" OnClientClick="return false;" runat="server" Text="Button" />
</div>
</form>
So, in this example, when Button1 is clicked normally, no postback occurs. When Button2 is clicked, a postback always occurs. Is this a bug or intended behavior?
© Stack Overflow or respective owner