asp.net under the onclientclick of the magical magic! _ Practical Tips
Source: Internet
Author: User
Do Web pages often with JavaScript, often use JavaScript to do some client authentication, but if our button with HTML control, the validation passed after the code can not call the background, if the server-side control, validation does not have to refresh the page, This is sometimes annoying, can not let the server Segment button to invoke the client's authentication, if the validation succeeds in the call to the server side of the method, so that both reduce the network transmission, to the user feel good.
When we use the template column to delete data generally return a dialog box to ask the user whether to confirm, in fact, we are by modifying the template column of the button's OnClientClick property to set its value back confirm ("You confirm the deletion of this record?"); We can analyze, confirm return is a bool value, if my button returned the result is also a bool should also be OK, I guessed right, such as the following code
function Judgeuserinput ()
{
bool result = true;
if (validation failed)
{
result = false;
Alert ("Please check that your input is correct");
}
return result;
}
So let's 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;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service