Wednesday, 1 February 2012

All Validation Control in Asp.Net and message are show in Validation summery

Source Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AllValidationDemo.aspx.cs" Inherits="AllValidationDemo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="*"
        style="z-index: 1; left: 13px; top: 53px; position: absolute; width: 5px"
        ForeColor="DarkCyan"></asp:RequiredFieldValidator>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="*"
         ForeColor="Red"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
        ControlToValidate="TextBox2" ErrorMessage="*" ForeColor="Blue"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
        ControlToValidate="TextBox3" ErrorMessage="*" ForeColor="Aqua"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
        ControlToValidate="TextBox4" ErrorMessage="*" ForeColor="Brown"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
        ControlToValidate="TextBox5" ErrorMessage="*"  ForeColor="AliceBlue"></asp:RequiredFieldValidator>
    <br />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ControlToValidate="TextBox4" ErrorMessage="Enter Valid emailID"
        SetFocusOnError="True"
        style="z-index: 1; left: 21px; top: 112px; position: absolute; right: 1106px"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        ForeColor="Red"></asp:RegularExpressionValidator>
    <asp:RangeValidator ID="RangeValidator1" runat="server"
        ControlToValidate="TextBox2"
        ErrorMessage="Range should be between 100 to 20000" MaximumValue="20000"
        MinimumValue="100"
        style="z-index: 1; left: 8px; top: 68px; position: absolute"
        ForeColor="Red" Type="Integer"></asp:RangeValidator>
    <br />
    <asp:TextBox ID="TextBox4" runat="server"
        style="z-index: 1; left: 230px; top: 106px; position: absolute"></asp:TextBox>
    <br />
    <asp:TextBox ID="TextBox3" runat="server"
        style="z-index: 1; left: 233px; top: 148px; position: absolute"></asp:TextBox>
    <br />
    <br />
    <br />
    <br />
    <br />
    <asp:TextBox ID="TextBox5" runat="server"
        style="z-index: 1; left: 232px; top: 183px; position: absolute"></asp:TextBox>
    <asp:Button ID="Button1" runat="server"
        style="z-index: 1; left: 259px; top: 222px; position: absolute" Text="Check" />
    <asp:ValidationSummary ID="ValidationSummary1" runat="server"
        ShowMessageBox="True"
       
        style="z-index: 1; left: 19px; top: 274px; position: absolute; height: 38px; width: 1275px"
        ShowSummary="False" />
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TextBox1" runat="server"
        style="z-index: 1; left: 231px; top: 40px; position: absolute"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"
        style="z-index: 1; left: 229px; top: 73px; position: absolute"></asp:TextBox>
    <asp:CompareValidator ID="CompareValidator1" runat="server"
        ControlToCompare="TextBox3" ControlToValidate="TextBox5"
        ErrorMessage="Name should be same"
        style="z-index: 1; left: 26px; top: 152px; position: absolute"
        ForeColor="Red"></asp:CompareValidator>
    </form>
</body>
</html>

Desgin Page



RunTime Design



C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AllValidationDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}



1 comment: