.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

how to give validation controls

Posted By: teja     Posted Date: March 04, 2013    Points:5   Category :ASP.Net
Hi,i have a registration page,which contains name,address,contact no,D.O.B,email id,user name,password,confirm password.I want to use validation controls for this.but i don't know how to use and which control is suitable to which column,am requesting you to v=can you please tell me the code.I mean for example if i leave the name column,i entered the address,then i want to display message as,name should not be blank,how should i get this,can you please tell me .

Author: Faizal             
Posted Date: March 05, 2013     Points: 20   

What validation control you want to use. or what control you want to validate?

Author: teja             
Posted Date: March 05, 2013     Points: 20   

Require dfield validator,regular expression,compare filed validator

Author: SailajaReddy             
Posted Date: March 06, 2013     Points: 20   

Hi teja,

If certain field is mandatory then use "RequiredFieldValidator"
To compare two values , use "CompareValidator" (Like password match)
For email - use "RegularExpressionValidator"

See the following code to use all these validators.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RegistrationForm_withvalidations.aspx.cs" Inherits="Forum_Topics_RegistrationForm_withvalidations" %>

<!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">
<form id="form1" runat="server">
Enter Name:<asp:TextBox id="txtName" runat="server"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RFV1" runat="server" ControlToValidate="txtName" ErrorMessage="Name is must"></asp:RequiredFieldValidator>
<br />
Enter Password:
<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
<br /><br />
Confirm Password:
<asp:TextBox ID="txtConfirmPwd" runat="server"></asp:TextBox>
<br /><br />
<asp:CompareValidator ID="CV1" runat="server" ControlToValidate ="txtConfirmPwd" ControlToCompare ="txtPwd" ErrorMessage="Password and Confirm Password does not match">
<br />
<asp:TextBox ID="txtEmail" runat="server" MaxLength="50" Width="140px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="*Invalid Email."


Author: teja             
Posted Date: March 06, 2013     Points: 20   

Thank you SailajaReddy

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend