Compare Validator In ASP.NET Web Forms | Form Validation | ASP.NET Web Forms

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="VALIDATION_FORM.aspx.cs" Inherits="VALIDATION_CONTROLS_PRACTICE.VALIDATION_FORM" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <style type="text/css">

        .auto-style1 {

            width: 83%;

        }

        .auto-style2 {

            height: 22px;

            width: 449px;

        }

        .auto-style3 {

            height: 22px;

            width: 126px;

        }

        .auto-style4 {

            width: 126px;

        }

        .auto-style5 {

            width: 449px;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <h2>STUDENTS REGISTRATION FORM</h2>

            <p>&nbsp;</p>

            <table class="auto-style1">

                <tr>

                    <td class="auto-style3">STUDENT NAME</td>

                    <td class="auto-style2">

                        <asp:TextBox ID="NameTextBox" runat="server" Width="235px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please Enter Student Name" ForeColor="Red" ControlToValidate="NameTextBox" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>

                    </td>

                </tr>

                <tr>

                    <td class="auto-style4">STUDENT EMAIL</td>

                    <td class="auto-style5">

                        <asp:TextBox ID="EmailTextBox" runat="server" Width="235px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please Enter Email" ForeColor="Red" ControlToValidate="EmailTextBox" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>

                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Email is Invalid" ForeColor="Red" ControlToValidate="EmailTextBox" Display="Dynamic" SetFocusOnError="true" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

                    </td>

                </tr>

                <tr>

                    <td class="auto-style4">RE-ENTER EMAIL</td>

                    <td class="auto-style5">

                        <asp:TextBox ID="ReEnterEmailTextBox" runat="server" Width="235px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please Re-Enter Email" ForeColor="Red" ControlToValidate="ReEnterEmailTextBox" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>

                        <asp:CompareValidator ID="CompareValidator1" runat="server" Display="Dynamic" ErrorMessage="Email is not identical" ForeColor="Red" ControlToCompare="EmailTextBox" ControlToValidate="ReEnterEmailTextBox" SetFocusOnError="true"></asp:CompareValidator>

                    </td>

                </tr>

                <tr>

                    <td class="auto-style4">&nbsp;</td>

                    <td class="auto-style5">

                        <asp:Button ID="Button1" runat="server" Text="SUBMIT" Height="40px" Width="99px" OnClick="Button1_Click"/>

                    </td>

                </tr>

            </table>

        </div>

    </form>

</body>

</html>

Above File is VALIDATION_CONTROLS_PRACTICE\VALIDATION_FORM.aspx
















using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(),"Scripts","<script>alert('YOUR FORM HAS BEEN SUBMITTED !!')</script>");
        }
    }
}
Above File is VALIDATION_CONTROLS_PRACTICE\VALIDATION_FORM.aspx.cs





Comments

Popular posts from this blog

Range Validator Control In ASP.NET Web forms | Form Validation | ASP.NET Web forms

Query String In ASP.NET Web Forms | State Management | ASP.NET | Web Forms

Validation Summary Control In ASP.NET Web forms | Form Validation | ASP.NET