I have an aspx page in which i have 3 asp.net text boxes and 1 asp.net button control.I want to do a client side validation before the post back happens when i click on the button . ie ; If the the page passes the validation check,then only i need to invoke the server side button click event.Can any one help me ? Thanks in advance
+2
A:
Define JS function:
function validate(){
//perform some validation
return $("#myTextbox").val()=="";
}
call it on button control onclick event="return DoValidation();"
If JS function will return false, postback will be canceled.
Arnis L.
2009-05-25 07:31:14
Then where i should mention the Server side event ?
Shyju
2009-05-25 07:33:53
Mention the server side OnClick and use OnClientClick to register client side javascript to the event.
Galilyou
2009-05-25 07:45:45
@7alwagy thx for your reply, i couldn't check stackoverflow faster.
Arnis L.
2009-05-25 14:56:49
A:
If you want to integrate with ASP.net validation, need to register your Javascript validator using RegisterValidator declaration.
Don't forget to valiate on the server-side too, as Javascript may be disabled.
James L
2009-05-25 07:34:07