ASP.NET Validator Controls – Part3

Posted: December 5, 2010 in ASP.NET
Tags:

A ValidationSummary control is displayed when the IsValid property of the page is false. It “polls” each of the validation controls on the page and aggregates the text messages exposed by each.  It does this through the Page.Validators collection; each validation control is added to this collection, and the validation summary can use this to determine which validators have errors.

When the user’s input is processed (for example, when the form is submitted), the Web Forms framework passes the user’s entry to the associated validation control or controls based on the ValidationGroup property. The validation controls test the user’s input and set a property to indicate whether the entry passed the validation test. After all validation controls have been processed, the IsValid property on the page is set; if any of the controls shows that a validation check failed, the entire page is set to invalid.

The following sample illustrates displaying errors with a ValidationSummary

<form id=”form1″ runat=”server”>
<div>
Age:<br />
<asp:TextBox runat=”server” id=”txt3″ />
<asp:RequiredFieldValidator runat=”server” id=”reqtxt3″ controltovalidate=”txt3″
errormessage=”Age” ValidationGroup=”234″ Display=”Static”>*</asp:RequiredFieldValidator>
<asp:RangeValidator runat=”server” id=”rangetxt3″ controltovalidate=”txt3″
errormessage=”Age – enter valid value (Between 1 to 120)”
MaximumValue=”120″ MinimumValue=”1″  Type=”Integer” ValidationGroup=”234″ Display=”Static”>*</asp:RangeValidator>
<br /><br />

Name:<br />
<asp:TextBox runat=”server” id=”txt1″ />
<asp:RequiredFieldValidator runat=”server” id=”reqtxt1″ controltovalidate=”txt1″ errormessage=”Name” ValidationGroup=”234″ Display=”Static”>*</asp:RequiredFieldValidator>
<br /><br />

<asp:Button runat=”server” id=”btnSubmit3″ text=”Ok” ValidationGroup=”234″/>
</div>

<div>
<asp:ValidationSummary ID=”valSum” runat=”server”
HeaderText=”You must enter a value in the following fields:”
Font-Names=”verdana”
Font-Size=”12″
DisplayMode=”BulletList”
ValidationGroup=”234″ />
</div>
</form>

References –

http://wiki.asp.net/page.aspx/237/validation-controls/
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/validation/default.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s