The ValidationSummary Control

ValidationSummary Control"-->

only for RuBoard

The ValidationSummary Control

The ValidationSummary control does not do actual evaluation like the previously mentioned controls. Instead it summarizes all the invalid controls after validation takes place. The ValidationSummary control loops through the validation controls array, gathers all the ErrorMessage properties of each invalid control, and displays the results in a specified manner.

The ValidationSummary control enables you to display the summary in a few different ways. This is accomplished by setting its DisplayMode property. There are three different "Modes" or Values to choose from for this property:

  • BulletList (default)

  • List

  • SingleParagraph

The ValidationSummary also has a ShowMessageBox property which is a Boolean . The ShowMessageBox property enables you to have the validation summary displayed in a pop-up message box. The default value for this attribute is false . Alternatively, the ShowSummary attribute, also Boolean, enables you to show the validation summary inline. The default value for this attribute is true.

If none of the above displays are adequate for your Web site, you can alternatively loop through the validation controls collection through code and create a custom summary.

In Listing 9.9, there is an example using the ValidationSummary control. In this example, there are two TextBox controls ”one for your first name and one for your second name . Both controls have RequiredFieldValidators wired to them.

Listing 9.9 The ValidationSummary Control
 01: <html> 02:  <body style="font-size:10"> 03:   <form runat="server"> 04: 05:    <h3>ValidationSummary</h3> 06: 07:    <asp:ValidationSummary 08:     runat="server" 09:     DisplayMode="BulletList" 10:     ShowMessageBox="true" 11:     ShowSummary="True" 12:     HeaderText="The following fields are missing:" 13:    /> 14: 15:    <p> 16: 17:    First Name: 18: 19:    <asp:TextBox 20:     runat="Server" 21:     id="txtFName" 22:    /> 23: 24:    <asp:RequiredFieldValidator 25:     runat="server" 26:     ControlToValidate="txtFName" 27:     ErrorMessage="* First Name is Required" 28:    /> 29: 30:    <br> 31: 32:    Last Name: 33: 34:    <asp:TextBox 35:     runat="server" 36:     id="txtLName" 37:    /> 38: 39:    <asp:RequiredFieldValidator 40:     runat="server" 41:     ControlToValidate="txtLName" 42:     ErrorMessage="* Last Name is Required" 43:    /> 44: 45:    <p> 46: 47:    <asp:Button 48:     runat="server" 49:     Text="Submit" 50:    /> 51: 52:   </form> 53:  </body> 54: </html> 

In Listing 9.9, we have two TextBox controls being validated . The first, (lines 19 “22), is wired to the RequiredFieldValidator on lines 24 “28. The second, (lines 34 “37), is wired to the RequiredFieldValidator on lines 39 “43. Finally, the ValidationSummary control is located on lines 7 “13. You'll notice right away that the ValidationSummary isn't wired to anything. This is because everything is done for you "behind the scenes." This is nice because you don't have to worry about writing any code ”hence, productivity is increased.

Let's try it out: Submit the page without filling out any fields. You will get a screen similar to Figure 9.6.

Figure 9.6. No fields have been filled out.
graphics/09fig06.gif

Because I have ShowMessageBox and ShowSummary both set to true you get an inline summary of all invalid controls, a message box, and individual control summaries. Do you think the user will get the point? Now fill in just the first name field and try to submit the page to see the effects. Finally, fill in all the fields and submit the page ”the page submits fine without any errors.

only for RuBoard


Programming Data-Driven Web Applications with ASP. NET
Programming Data-Driven Web Applications with ASP.NET
ISBN: 0672321068
EAN: 2147483647
Year: 2000
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net