Vous êtes sur la page 1sur 4

EXERCISE 1 : Validation Controls

AIM : To demonstrate the use of Validation Controls used in ASP.NET

EXPLANATION : ASP.Net validation controls validate the user input data to ensure that
useless, unauthenticated or contradictory data don.t get stored.
ASP.Net provides the following validation controls:
1. RequiredFieldValidator
2. RangeValidator
3. CompareValidator
4. RegularExpressionValidator
5. CustomValidator
6. ValidationSummary

PROCEDURE :
Step1:- Open visual studio-->File-->New-->project--> Select ASP.NET Empty Website
Change Language to Visual Basic Press OK-->

Step 2: In Solution Explorer-->Add New Web form-->and drag and drop the following
controls:
4 Label boxes
5 Text Boxes
1 Button and
4 Required Field Validation controls
1 Compare Validator
1 Range Validator

Step3:- Now change the following properties which are given below for every control:-
1) RequiredFieldValidator:- Go property of this control and change:-
ControlToValidate --> Text Box, Which is to be validated.

F:\Jerald\Ex1 Page 1 of 4
Error Message --> Which you want to show on the screen.
Text --> * (mandatory field),if required

2) CompareValidator :- Go property of this control and change:-


Control To Compare-->Which control is to be compared.
ControlToValidate --> Text Box, Which you want to validate.
Error Message --> Which you want to show on the screen.
Text --> * (mandatory field),if required

3) RangeValidator :- Go property of this control and change:-


ControlToValidate --> Text Box, Which you want to validate.
Error Message --> Which you want to show on the screen.
Maximum Value:-Enter Maximum value limit
Minimum Value :- Enter Minimum value limit.
Text --> * (mandatory field),if required

Step4:- Now Run the Application (press F5)-->and enter the required fields.

Step5:- Now Click the SUBMIT button--> then we will see the output.

SOURCE CODE :
VALIDATION.ASPX
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="validation.aspx.vb"
Inherits="_Default" %>
<!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 id="Head1" runat="server">
<title>Validation Control demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Style="top: 239px; left: 75px; position: absolute;
height: 22px; width: 128px; z-index: 100;" Text="Enter your Age:"></asp:Label>
<asp:Label ID="Label2" runat="server" Style="top: 94px; left: 81px; position: absolute;
height: 22px; width: 128px; z-index: 101;" Text="Enter your name:"></asp:Label>
</div>
<asp:TextBox ID="TextBox1" runat="server" Style="top: 95px; left: 250px; position:
absolute; height: 22px; width: 128px; z-index: 102;"></asp:TextBox>
<p><asp:TextBox ID="TextBox4" runat="server" Style="top: 195px; left: 249px; position:
absolute; height: 22px; width: 127px; z-index: 103;"></asp:TextBox>
</p>
<p> <asp:Label ID="Label3" runat="server" Style="top: 148px; left: 76px; position:
absolute; height: 22px; width: 128px; z-index: 104;" Text="Enter Password:"></asp:Label>
</p>

F:\Jerald\Ex1 Page 2 of 4
<p> <asp:TextBox ID="TextBox3" runat="server" Style="top: 146px; left: 249px; position:
absolute; height: 22px; width: 127px; z-index: 105;" TextMode="Password"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label4" runat="server" Style="top: 197px; left: 75px; position: absolute;
height: 22px; width: 128px; z-index: 106;" Text="Confirm Password:"></asp:Label>
</p><asp:TextBox ID="TextBox2" runat="server" Style="top: 236px; left: 250px; position:
absolute; height: 22px; width: 127px; z-index: 107;"></asp:TextBox>
<p><asp:Button ID="submit" runat="server" Style="top: 295px; left: 275px; position:
absolute; z-index: 108;" Text="Submit" Height="32px" OnClick="Button1_Click"
Width="106px" />
</p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" Style="top: 390px;
left: 44px; position: absolute; height: 38px; width: 625px; z-index: 109;" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Name is Mandatory" Style="z-index: 110; left:
399px; position: absolute; top: 98px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Password is Required" Style="z-index: 111;
left: 401px; position: absolute; top: 151px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Reenter Password" Style="z-index: 112; left:
402px; position: absolute; top: 201px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Age is required" Style="z-index: 113; left:
399px; position: absolute; top: 239px"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Age between 18 and 60" MaximumValue="60"
MinimumValue="18" Style="z-index: 114; left: 516px; position: absolute; top: 238px"
Type="Integer" Width="173px"></asp:RangeValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox2" ControlToValidate="TextBox3" ErrorMessage="Password
mismatch" Style="z-index: 116; left: 539px; position: absolute; top:
201px"></asp:CompareValidator>
</form>
</body>
</html>

VALIDATION.ASPX.VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles submit.Click
Response.Write("Updation")
End Sub

F:\Jerald\Ex1 Page 3 of 4
OUTPUT

F:\Jerald\Ex1 Page 4 of 4

Vous aimerez peut-être aussi