.Net Practical 21


Practical : 21
Subject : .Net

Aim : Write a program in C# to demonstrate the use of all the validation controls for a user registration page.



Source Code :
//file.aspx 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pra21.aspx.cs" Inherits="dotnet008asp.pra21" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>pratik008</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Name&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtname" Display="Dynamic" EnableViewState="False" ErrorMessage="Required" ForeColor="Red"></asp:RequiredFieldValidator>
        </div>
        <p>
            Mobile&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtmobile" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtmobile" Display="Dynamic" EnableViewState="False" ErrorMessage="Required" ForeColor="Red"></asp:RequiredFieldValidator>
        </p>
        <p>
            Email&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtemail" Display="Dynamic" EnableViewState="False" ErrorMessage="Required" ForeColor="Red"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtemail" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        </p>
        <p>
            Age&nbsp;&nbsp;&nbsp;&nbsp; <asp:TextBox ID="txtage" runat="server"></asp:TextBox>
            <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtage" Display="Dynamic" ErrorMessage="RangeValidator(20-30)" ForeColor="Red" MaximumValue="30" MinimumValue="20"></asp:RangeValidator>
        </p>
        <p>
            Password&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtpwd" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtpwd" Display="Dynamic" EnableViewState="False" ErrorMessage="Required" ForeColor="Red"></asp:RequiredFieldValidator>
        </p>
        <p>
            Confirm Password&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:TextBox ID="txtconfirmpwd" runat="server"></asp:TextBox>
            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtpwd" ControlToValidate="txtconfirmpwd" Display="Dynamic" ErrorMessage="CompareValidator (password)" ForeColor="Red"></asp:CompareValidator>
        </p>
        <p>
&nbsp;<asp:Button ID="Button1" runat="server" Text="submit" />
        </p>
    </form>
</body>
</html>

//web.config
<configuration>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>

Output : 


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment