C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Validations »

How to use CompareValidator for DataType check and value range


Posted Date: 04 Jun 2009    Resource Type: Code Snippets    Category: Validations
Author: hiteshMember Level: Gold    
Rating: 1 out of 5Points: 10



First example shows how to check the DataType of a value for a particular control using CompareValidator.


Percentage: <asp:TextBox ID="txtPerc" runat="server" Columns="4" MaxLength="3" Width="30px" >
</asp:TextBox> %

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtPerc" Text="*" ErrorMessage="Please enter percentage." >
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cv1" runat="server" ControlToValidate="txtPerc"
Text="*" ErrorMessage="Please enter integer value only (this period)."
Operator="DataTypeCheck" Type="Integer">
</asp:CompareValidator>



Second example shows how to check, if a value is "GreaterThanEqual" to 5. You can use other Operators as well.



Number of Attemps:
<asp:TextBox ID="txtAttempt" runat="server" Columns="4" MaxLength="3" Width="30px" >
</asp:TextBox>
<asp:CompareValidator ID="cv2" runat="server"
ControlToValidate="txtAttempt"
Text="*" ErrorMessage="Number of Attempts must be greater than or equal 5"
Operator="GreaterThanEqual" ValueToCompare="5">
</asp:CompareValidator>



Validation is quite simple to implement with asp.net validation controls.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
CompareValidator for DataType check  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to use RangeValilator control with Dropdown
Previous Resource: validating textBox control alphabets and underscroe and dot using Javascript
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use