Topic: Validation - Canceling validation
Share/Save/Bookmark
Canceling Validation
 
Because validation occurs before the server processes the page, a user can become trapped by validation unless you provide
a way to cancel validation without posting back.
 
To let the user cancel validation, provide a Submit HTML control that sets the "Page_ValidationActive" attribute, as shown
below in the following HTML code:
 
                      v------------------------------------v
<INPUT id="butCancel" onclick="Page_ValidationActive=false;" style="Z INDEX :114 LEFT: 386px; WIDTH: 62px type="submit" value="Cancel">
 
The preceding button definition cancels validation and posts the page back to the server. You can determine whether the user has
cancelled the operation by checking the "Page" object's "IsValid" property in the "Page_Load" event procedure. You have to
revalidate the page because canceling validation sets "IsValid" to "True". The following code shows how to check whether the
user cancelled validation:
 
private void Page_Load(object sender, System.EventArgs e)
{
   // Validate in case user cancelled validation
   if (Page.IsPostBack)
   {
      Page.Validate();
      if (!Page.IsValid)
         // User cancelled validation so send to another page
         Response.Redirect("Default.htm");
   }
}