Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
on a button click client side validation of text boxes is performed i want to execute server side code after validation. if validation fails the control remains on client side. how can i do this?
Posted

1 solution

If you are using asp button, then the javaScript need to be called on the event OnClientClick[^].

Then on that call javaScript function to validate like below...
XML
<asp:Button ID="Button1"
       text="Open Web site"
       onclientclick="return Validate()"
       runat="server" onclick="Button1_Click" />


Now the javaScript function will validate and return appropriate boolean value like below...
JavaScript
function Validate(){
    if validated
        return true;
    else
        return false;
}


So, when it is not validated it will return false and the service side event Button1_Click will not fire and if it returns true, then the server side event will get fired.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900