In asp.net, Page. Validate () and Page. IsValid are used for server-side verification.

Source: Internet
Author: User
Generally, we can set various verification controls on ASPX to check the input items of the form. However, this function is over after the JavaScript is disabled on the client.

ASP. NET will execute Page after the Page_Load event. validate () starts the server-side verification code of the verification control, and the verification result is placed in Page. isValid, so that we can use Page in subsequent code. isValid to determine whether all data is valid.

If we want to know whether illegal data exists in the Page_Load event, we need to first call Page. Validate () in the Page_Load event to check.

The following is a simple code for your reference only:

Code
// Before Page. Validate is executed
Protected void Page_Load (object sender, EventArgs e)
{
If (IsPostBack = true)
{
Page. Validate ();
If (Page. IsValid = true)
{// Verification Successful
DoSomeThing ();
}
Else
{// Verification Failed
Return;
}
}
}

// After Page. Validate has been executed
Protected void btnSave_Click (object sender, EventArgs e)
{
If (Page. IsValid = true)
{// Verification Successful
DoSomeThing ();
}
Else
{// Verification Failed
Return;
}
}

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.