views:

636

answers:

2

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.
Then where i should mention the Server side event ?
Shyju
Mention the server side OnClick and use OnClientClick to register client side javascript to the event.
Galilyou
@7alwagy thx for your reply, i couldn't check stackoverflow faster.
Arnis L.
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