Web Studyaspnet.blogspot.com Babyneed.blogspot.com

ASP.Net Web Developer Guide

Power By: eXTReMe Tracker Powered by Blogger  
 
 
 
 

 

 
Important Links
 
   
     
 
Sitemap
 
   
   
 
Reference
 
   

Sunday, March 26, 2006

The ValidationSummary Control (Chapter 3)

The ValidationSummary control enables us to display all errors in a given location. It displays the “errorMessage” properties of respective controls in the summary report. Since the error messages are displayed in the summary, often we suppress the detailed error message in the individual ValidatorControls by placing an asterisk (*) or a short message right after the validator control’s start-tag. Major properties of the ValidationSummary control are the following:
  • headerText This is simply a header.

  • displayMode Displays the errors in one of the following ways:

  • List

  • BulletList (default)

  • Singleparagraph

  • ShowSummary: (True or False) This property can be used to display or hide the summary report programmatically.
Figure 3.62 illustrates the use of a ValidationSummary control. In our example, we have defined the ValidationSummary control as follows.
<asp:ValidationSummary id="valSummary" runat="server"
headerText="Please correct the following errors"
display="static" showSummary= "True" />
Figure 3.62 Using the ValidationSummary Control

The complete code for the application is shown in Figure 3.63

Figure 3.63 The Complete Code for the Application (Validator8.aspx)
<!—- Chapter3\Validator8.aspx —>
<%@ Page Language="VB" Debug="true" %>
<html><head</head>
<title>Example on ValidationSummary control </title>
<body><form runat="server">
Enter Your Name:
<asp:TextBox id="txtName" rows="1" width="100" 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 ="60" 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 ="60" 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 ="60" runat="server" />
<asp:RangeValidator id="ranvDependents" runat="server"
backcolor="salmon" forecolor="blue" bordercolor="green"
borderstyle="Solid" borderwidth="5" font-bold="True"
font-italic="True" font-size="14" height="20"
tooltip="Cannot have more than 20 dependents."
text="Bad Number. Must be less than 21" width="250"
display="dynamic" controlToValidate="txtDependents"
errorMessage= "Number of dependents must be from 0 to 20"
type="Integer" minimumValue="0" maximumValue="10">*
</asp:RangeValidator><br>
What is your Department Number?
<asp:TextBox id="txtDeptNum" width ="60" runat="server" />
<asp:CustomValidator id="cusvDeptNum" runat="server"
display="dynamic" controlToValidate="txtDeptNum"
onServerValidate="validateDeptNum"
ClientValidationFunction="checkModTen"
errorMessage= "Dept. Number must be a multiple of 10" >*
</asp:CustomValidator><br>
<asp:Button id="btnSubmit" runat="server" text="Submit"/><br><br>
<asp:ValidationSummary id="valSummary" runat="server"
headerText="Please correct the following errors" display="static"
showSummary= "True" /><br>
</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>
<script language="javascript">
function checkModTen(source, s)
{ var y=parseInt(s.Value);
if (isNaN(y) && !((y % 10) == 0))
s.IsValid=false;
else
s.IsValid=true;
}
</script>

0 Comments:

Post a Comment

<< Home