Microsoft KB Archive/316712

= INFO: ASP.NET ValidationSummary Web Form Control =

Article ID: 316712

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q316712



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.



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.  First Name:   

Age:   

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

<asp:ValidationSummary id=&quot;valSum&quot; DisplayMode=&quot;BulletList&quot; runat=&quot;server&quot; HeaderText=&quot;Summary of Validation Errors:&quot; Font-Name=&quot;verdana&quot; Font-Size=&quot;12&quot;/> <asp:Button id=btnValidate text=&quot;Validate&quot; runat=server />

<div class="references_section">