Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 316712 - Last Review: February 23, 2007 - Revision: 3.3
INFO: ASP.NET ValidationSummary Web Form Control
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.
<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>
REFERENCES
For additional information about Validation controls, browse to the following MSDN Web sites:
APPLIES TO
- Microsoft ASP.NET 1.1
- Microsoft ASP.NET 1.0
| kbinfo kbservercontrols kbvalidation kbwebforms KB316712 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please