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 » ASP.NET WebForms »

Custom Validator


Posted Date: 08 Dec 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: SravyaMember Level: Gold    
Rating: 1 out of 5Points: 10



<%@ Page Language="VB" Debug="true" %>
<html><head</head>
<title>Example on CustomValidator</title>
<body>
<form runat="server">
Enter Your Name:
<asp:TextBox id="txtName" rows="1 " width="60"
runat="server"/>
<asp:RequiredFieldValidator id="validTxtName"
runat="server"
controlToValidate="txtName"
errorMessage="Name must be entered"
display = "static">
</asp:RequiredFieldValidator></br>
Hours worked?
<asp:TextBox id="txtH" width ="40"
runat="server" />
<asp:RequiredFieldValidator id="validTxtH"
runat="server"
controlToValidate="txtH"
errorMessage="Hours must be entered"
display = "static">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="regvH"
runat="server"
display = "static"
controlToValidate = "txtH"
errorMessage="Hours must be 1-3 digits only"
validationExpression="\d{1,3}">
</asp:RegularExpressionValidator></br>
Hourly Rate?
<asp:TextBox id="txtR" width ="40"
runat="server" />
<asp:CompareValidator id="comvR"
runat="server"
display = "static"
controlToValidate = "txtR"
errorMessage="Rate must be numeric"
type = "Double"
operator="DataTypeCheck">
</asp:CompareValidator></br>
Number of Dependents:
<asp:TextBox id="txtDependents" width ="40"
runat="server" />
<asp:RangeValidator id="ranvDependents"
runat="server"
display = "static"
controlToValidate = "txtDependents"
errorMessage="Must be from 0 to 10"
type = "Integer"
minimumValue=0
maximumValue=10>
</asp:RangeValidator></br>
What is your Department Number?
<asp:TextBox id="txtDeptNum" width ="40"
runat="server" />
<asp:CustomValidator id="cusvDeptNum"
runat="server"
display = "static"
controlToValidate = "txtDeptNum"
onServerValidate = "validateDeptNum"
errorMessage="Must be in multiples of 10" >
</asp:CustomValidator></br>
<asp:Button id="btnSubmit" runat="server"
text="Submit" />
</form></body></html>

<script language="VB" runat="server">
Sub validateDeptNum(source As Object, s as ServerValidateEventArgs)
If (CInt(s.Value) Mod 10) = 0 Then
s.IsValid= True
Else
s.IsValid=False
End If
End Sub
</script>


Example of Custom Validator



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.
Example of Custom Validator  .  Custom validator  .  

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: Range Validator
Previous Resource: How to bind data to Event calendar
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use