Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » Dotnet




 Page 1 of 1 [ 4 posts ] 



Author Message
 Post subject: comparin the validator 4 2 yr drop down list
 Post Posted: Sat Oct 24, 2009 8:19 am 
Offline

Joined: Sat Feb 21, 2009 12:31 pm
Posts: 67
Hi friends,

I m havin a 2 yr drop down lists...bgin year, end year. i need to validate to
dropdownlists, endy earmust not be less than begin year.
however i validated usin the compare validator in this way :D

Code:
# <tr> 
#                     <td align="left"> <asp:Label ID="dodeathlbl" runat="server" AssociatedControlID="yobddl" Text="Date of Death" /></td> 
#                     <td><asp:Label id="fromDate" Text="Year Begin"  runat="server" Width="140" /></td> 
#                     <td align="left"><users:YearDropdownList runat="server" ID="yodfromddl" /> </td> 
#                     <td><asp:Label id="toDate"  Text="Year End" runat="server" Width="140px" /></td> 
#                     <td align="left"><users:YearDropdownList runat="server" ID="yodtoddl" /> </td> 
#                    </tr> 
#                     <div> 
#                               
#                 <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="yodfromddl" 
#                     ControlToValidate="yodtoddl"  ErrorMessage="Year End can not be less than Year Begin" Operator="LessThan" Type="Date" />   



It is giving an exception .unable to be validated. why ?? How could i validate 4 two
year dropdownlists.??:)


Top 
 Post subject: Re: comparin the validator 4 2 yr drop down list
 Post Posted: Sat Oct 24, 2009 8:20 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
I watch ur year drop down lists r user controls... A Compare Validator could
only be used wid the ASP.NET web controls...



Thanks in advance .


Top 
 Post subject: Re: comparin the validator 4 2 yr drop down list
 Post Posted: Sat Oct 24, 2009 8:20 am 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
I just think that u should include Value To Compare which was "Value"

Code:
ValueToCompare="Value"


Top 
 Post subject: Re: comparin the validator 4 2 yr drop down list
 Post Posted: Sat Oct 24, 2009 8:20 am 
Offline

Joined: Sat Feb 21, 2009 12:31 pm
Posts: 67
I was not sure how 2 get da Compare Validator 2 work, however it would be very
easy 2 set up a CustomValidator wid a OnServerValidate event 2 do da comparison.

Somethin like this:

Code:
   1. <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="yodfromddl" ErrorMessage="Year End can not be less than Year Begin" OnServerValidate="CustomValidator1_ServerValidate"/> 


Code:
   1. protected void CustomValidator1_ServerValidate(object sender, SeverValidateEventArgs e) 
   2. { e.IsValid = !(Int.Parse(yodfromddl.SelectedValue)>Int.Parse(yodtoddl.SelectedValue));} 


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 4 posts ] 




Board index » Server Side Development » Dotnet


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron