EugeneBarnard
Programmer
Hi
I created an asp.net2 page similar to the one below that contains two or more buttons, eg a submit button (type=submit) and a cancel button (type=button). If I run the code from an asp.net 2 page, the cancel button incorrectly fires the ValidateForm before posting back to the server. The same code works when using asp.net 1.1, ie the submit button fires the ValidateForm method and the cancel button performs a postback without firing the onsubmit event.
As far as I know, the onsubmit javascript event should not be fired when the submit() method is called from code.
Can anyone tell me what I am doing wrong?
Thanks
Eugene
I created an asp.net2 page similar to the one below that contains two or more buttons, eg a submit button (type=submit) and a cancel button (type=button). If I run the code from an asp.net 2 page, the cancel button incorrectly fires the ValidateForm before posting back to the server. The same code works when using asp.net 1.1, ie the submit button fires the ValidateForm method and the cancel button performs a postback without firing the onsubmit event.
As far as I know, the onsubmit javascript event should not be fired when the submit() method is called from code.
Can anyone tell me what I am doing wrong?
Thanks
Eugene
Code:
<html>
<head runat="server">
<script>
function ValidateForm(pfrm)
{
alert('Validate form event fired');
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server" onsubmit="return ValidateForm(this);">
<asp:TextBox ID="txtTextbox1" runat="server"></asp:TextBox> <br />
<asp:TextBox ID="txtTextbox2" runat="server"></asp:TextBox> <br />
<asp:Button ID="btnSubmit" runat="server" Text="submit" OnClick="btnSubmit_Click" />
<input type="button" id="btnCancel" runat="server" value="cancel" onserverclick="btnCancel_ServerClick" />
</form>
</body>
</html>