Page 83 - DCAP312_WEB_TECHNOLOGIES_II
P. 83
Unit 4: Advanced Server Controls
<p> Notes
<asp:Label id= “Label1” runat= “server”></asp:Label>
</p>
</form>
</body>
</html>
2. The Validation Summary Control
The Validation Summary server control works with all the validation server controls on the
page. It takes all the error messages that the other validation controls send back to the page and
puts them all in one spot (that we specify) on the page. These error messages can be displayed
in a list, bulleted list, or paragraph.
We can use the Validation Summary server control in a number of ways, but the example shows
us how to use it in a simple manner. For this example, two text boxes on the page are associated
with a RequiredFieldValidator control. When an error is triggered, not only does it display the
error next to the text box itself, it also displays it in a summary at the bottom of the ASP.NET
page. (See Figure 4.7)
Having a Summary of Errors Appear on the Screen
<p>First name
<asp:TextBox id= “TextBox1” runat= “server”></
asp:TextBox>
<asp:RequiredFieldValidator id= “RequiredFieldValidator1”
runat= “server” ErrorMessage= “You must enter your first
name”
ControlToValidate= “TextBox1”></asp:RequiredFieldValidator>
</p>
<p>Last name
<asp:TextBox id= “TextBox2” runat= “server”></asp:TextBox>
<asp:RequiredFieldValidator id= “RequiredFieldValidator2”
runat= “server” ErrorMessage= “You must enter your last
name”
ControlToValidate= “TextBox2”></asp:RequiredFieldValidator>
</p>
<p>
<asp:Button id= “Button1” onclick= “Button1_Click” runat=
“server”
Text= “Submit”></asp:Button>
</p>
<p>
<asp:ValidationSummary id= “ValidationSummary1” runat=
“server”
HeaderText= “You received the following errors:”>
</asp:ValidationSummary>
</p>
<p>
<asp:Label id= “Label1” runat= “server”></asp:Label>
</p>
LOVELY PROFESSIONAL UNIVERSITY 77