Friday, February 25, 2011

asp.net Validation on DropDownList box

1 comments
Many beginners found problem at the time of to do validation on dropdownlist control.

Let say if in dropdown list items first item is for indicating "select value" follow by others list items. Many developer validate at coding side that if user has selected any items except first value("Select value") but it will do post back & check on server side & resulting take more time.

You can do client validation following way using Rangevalidator

<asp:DropDownList runat="server" ID="ddl1" >
       
<asp:ListItem Value="0" Text="Select value" />
       
<asp:ListItem Value="1" Text="text1" />
       
<asp:ListItem Value="2" Text="text2" />
   
</asp:DropDownList>
   
<asp:RangeValidator ErrorMessage="Please select value" ControlToValidate="ddl1" runat="server"
       
MinimumValue="1" MaximumValue="100000000" Type=Integer />
   
<asp:Button Text="text" runat="server"  /> 

Here you have to use Range validator with dropdown list & set mininmum value greater then 0 & maximum value to set any max value , aslo provide type value of min & max and that is integer

Hello to beginners!!!

0 comments
Hello to everyone,
I am software engineer and working on microsoft technology it good industry from last 2 years,
I am starting this blog to share my knowledge that can be helpful to beginner.
So I'll try my level best to provide you good stuff here

Regards
Arun