Webpages often have to deal with JavaScript and often use JavaScript for client-side verification. However, if our buttons use HTML controls, after verification is passed, the backend cannot be called. Code If you use a server-side control to refresh the page if the verification fails, this is sometimes annoying. Can you have the server segment button call client verification, if the method on the server is called after the verification is successful, the network transmission will be reduced and the user will feel better.
When we delete data using the template column, a dialog box is usually returned asking the user for confirmation, in fact, we set the value to return confirm by modifying the onclientclick attribute of the button in the template column ("are you sure you want to delete this record?"); we can analyze it, confirm returns a bool value. If the result returned by my button is also a bool, I guess it is correct. For example, there are some codes below:
Function judgeuserinput ()
{
Bool result = true;
If (Verification Failed)
{
Result = false;
Alert ("check whether your input is correct ");
}
Return result;
}
Set the button onclientclick to return judgeuserinput!
Function validion (RegEx, elementname, alertstr)
{
VaR htmlobj = Document. getelementbyid (elementname );
If (htmlobj. value! = "")
{
If (RegEx. Test (htmlobj. Value ))
{
Return true;
}
Else {alert (alertstr );
Return false;
}
}
If (htmlobj. value = "")
{
Return true;
}
}
Then