Validation ASP.Net Tutorial

File: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="RegularExpressionTest" %>



    Regular Expression Test


    
    

                             runat="server" 
                     Width="192px">
                            runat="server" 
                    Width="138px" 
                    Text="Set This Expression" 
                    CausesValidation="False" 
                    OnClick="cmdSetExpression_Click">
        
                           runat="server" 
                   Height="21px" 
                   Width="512px" >Current Expression: (none)
                           runat="server" >New Expression:
    
    

      
                                            runat="server" 
                                      EnableClientScript="False" 
                                      ErrorMessage="Failed Validation" 
                                      ControlToValidate="txtValidate">
      
      
      Test Current Expression:
    

    


File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class RegularExpressionTest : System.Web.UI.Page
{
  protected void cmdSetExpression_Click(object sender, EventArgs e)
  {
    TestValidator.ValidationExpression = txtExpression.Text;
    lblExpression.Text = "Current Expression: ";
    lblExpression.Text += txtExpression.Text;
  }
}