0% found this document useful (0 votes)
27 views

Range V Lid at or Example

The document describes using range validators in ASP.NET to validate user input fields. It includes code for an ASP.NET web form with text boxes for age and date, along with range validators to check that age is between 1-100 and date is within 2017. The form also has a submit button that checks for valid input using the Page.IsValid property and displays a status message.

Uploaded by

Abdul waris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Range V Lid at or Example

The document describes using range validators in ASP.NET to validate user input fields. It includes code for an ASP.NET web form with text boxes for age and date, along with range validators to check that age is between 1-100 and date is within 2017. The form also has a submit button that checks for valid input using the Page.IsValid property and displays a status message.

Uploaded by

Abdul waris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Rang Validator Control

Range Validator.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RangeValidator.aspx.cs"


Inherits="WebApplication1.RangeValidator" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<b>Age</b>
</td>
<td>:<asp:TextBox ID="txtAge" runat="server"
Width="150px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="Please Enter an Age Between 1 t0 100!" ControlToValidate="txtAge"
MinimumValue="1" MaximumValue="100" Type="Integer" ForeColor="Red"
Display="Dynamic"></asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Age Field is required!" ControlToValidate="txtAge"
ForeColor="Red" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<b>Date</b>
</td>
<td>:<asp:TextBox ID="txtDate" runat="server"
Width="150px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator2" runat="server"
ErrorMessage="Please Enter a Valid Date of Year 2017!" ControlToValidate="txtDate"
MinimumValue="01/01/2017" MaximumValue="12/30/2017" Type="Date" ForeColor="Red"
Display="Dynamic"></asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="Date Field is required!" ControlToValidate="txtDate"
ForeColor="Red" Display="Dynamic"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnsave" runat="server" Text="Save" Width="100px"
OnClick="btnsave_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Font-
Bold="true"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

RangValidator.aspx.cs

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

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

protected void btnsave_Click(object sender, EventArgs e)


{
if (Page.IsValid)
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "Data has been Successfully Stored!";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "Validation Failed Data Not Saved!";
}
}
}
}

You might also like