Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

INFO: ASP.NET ValidationSummary Web Form Control


View products that this article applies to.

Summary

There are six Web server controls that you can use to validate input on your Web Form pages. This article discusses the ValidationSummary control.

↑ Back to the top


More information

The ValidationSummary control is used to summarize the error messages from all validators on a Web page in a single location. The summary can be displayed as a list, a bulleted list, or as a single paragraph based on the DisplayMode property. The summary can be displayed on the Web page and in a message box when you set the ShowSummary and ShowMessageBox properties accordingly.

The following sample code demonstrates uses of the RequiredFieldValidator, RangeValidator, and ValidationSummary controls. If a value is not entered in the Name, Age, or Height text boxes, or if a valid height is not entered in the Height text box, the ValidationSummary control lists a summary of the validation errors.

NOTE: When you set the ShowMessageBox value to True on the ValidationSummary control, the summary is displayed in a client-side message box.
<html>
	<body>
	    <form runat=server id=form1>
				
	       <asp:Label ID="lblName" Runat=server>First Name:</asp:Label>
                <asp:TextBox ID="txtName" Runat=server></asp:TextBox>			
                <asp:RequiredFieldValidator 
                    id="RequiredFieldValidatorName"
                    ControlToValidate="txtName" 
                    ErrorMessage="First Name field is empty"
                    Display="Static"
                    InitialValue="" Width="100%" runat=server>
                </asp:RequiredFieldValidator><br>

	       <asp:Label ID="lblAge" Runat=server>Age:</asp:Label>
	       <asp:TextBox ID="txtAge" Runat=server></asp:TextBox>			
                <asp:RequiredFieldValidator 
                    id="RequiredfieldvalidatorAge"
                    ControlToValidate="txtAge" 
                    ErrorMessage="Age field is empty"
                    Display="Static"
                    InitialValue="" Width="100%" runat=server>
                </asp:RequiredFieldValidator><br>

               <asp:Label ID="lblHeight" Runat=server>Height:</asp:Label>
	      <asp:TextBox ID="txtHeight" Runat=server></asp:TextBox>			
		<asp:RequiredFieldValidator 
                    id="RequiredfieldvalidatorHeight"
                    ControlToValidate="txtHeight" 
                    ErrorMessage="Height field is empty"
                    Display="Static"
                    InitialValue="" Width="100%" runat=server>
                </asp:RequiredFieldValidator>
			
               <asp:RangeValidator 
                   id="RangeValidatorHeight"
                   ControlToValidate="txtHeight" 
                   ErrorMessage="Incorrect value for the height field"
                   Display="Static"
                   Type="Integer"
		 MinimumValue="1"
		 MaximumValue="10"                
                   Width="100%" runat=server>
              </asp:RangeValidator><br>

              <asp:ValidationSummary 
                  id="valSum" 
                  DisplayMode="BulletList" 
                  runat="server"
                  HeaderText="Summary of Validation Errors:"
                  Font-Name="verdana"                 
                  Font-Size="12"/><br>
                
              <asp:Button id=btnValidate text="Validate" runat=server />
	   </form>
	</body>
</html>
				

↑ Back to the top


Keywords: KB316712, kbwebforms, kbvalidation, kbservercontrols, kbinfo

↑ Back to the top

Article Info
Article ID : 316712
Revision : 7
Created on : 2/23/2007
Published on : 2/23/2007
Exists online : False
Views : 430