Return to the menu   Select another DES Module

Demonstrates how another control can be displayed along with the ValidationSummary

The ValidationSummary control may not be the only element on the page that you want to appear while errors are shown. Perhaps you want a label near the top of the page to say “Fix the errors”, while the ValidationSummary appears near to the Submit button. Use the RelatedControlID property to let the ValidationSummary control the visibility of another control.

The Related Control can show when the ValidationSummary is hidden or visible depending on the RelatedControlDisplayMode property. This gives you several ways to communicate errors:

  • ErrorsShown - Show a message elsewhere on the page telling the user to fix errors. This is the default.
  • AllErrorsFixed - Show a message when errors were shown but now cleaned up.
  • NoErrorsShown - Show a message when there are no errors on the page, even before any data entry.


Controls

Notice the initial message shown in the RelatedControlDisplayMode="NoErrorsShown" example.
Click the Submit control to display the ValidationSummary controls. Fix errors by entering text into the textboxes.





RelatedControlDisplayMode="ErrorsShown" (the default)



RelatedControlDisplayMode="AllErrorsFixed"



RelatedControlDisplayMode="AllErrorsFixed" and AutoUpdate=True

Use AutoUpdate=True to make it a little more interactive as the errors are cleaned up.


RelatedControlDisplayMode="NoErrorsShown"

No errors to report

Source Code (C#)

<script runat="server">
protected void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save your data here } }
</script> Notice the initial message shown in the RelatedControlDisplayMode="NoErrorsShown" example.<br/> Click the Submit control to display the ValidationSummary controls. Fix errors by entering text into the textboxes.<br/><br/> <des:TextBox ID="TextBox1" runat="server" /> <des:RequiredTextValidator ID="RequiredTextValidator1" runat="server" ControlIDToEvaluate="TextBox1" ErrorMessage="Required" /> <br/> <des:TextBox ID="TextBox2" runat="server" /> <des:RequiredTextValidator ID="RequiredTextValidator2" runat="server" ControlIDToEvaluate="TextBox2" ErrorMessage="Required" /> <br/> <des:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /><br/> <hr/> <h2>RelatedControlDisplayMode="ErrorsShown" (the default)</h2> <des:ValidationSummary ID="ValidationSummary1" runat="server" RelatedControlID="Label1" RelatedControlDisplayMode="ErrorsShown" /> <asp:Label ID="Label1" runat="server" Text="Please fix the errors" ForeColor="Green"></asp:Label><br/> <br/> <h2>RelatedControlDisplayMode="AllErrorsFixed"</h2> <des:ValidationSummary ID="ValidationSummary2" runat="server" RelatedControlID="Label2" RelatedControlDisplayMode="AllErrorsFixed" /> <asp:Label ID="Label2" runat="server" Text="Thanks for fixing the errors" ForeColor="Maroon"></asp:Label><br/><br/> <h2>RelatedControlDisplayMode="AllErrorsFixed" and AutoUpdate=True</h2> Use AutoUpdate=True to make it a little more interactive as the errors are cleaned up.<br/> <des:ValidationSummary ID="ValidationSummary3" runat="server" RelatedControlID="Label3" RelatedControlDisplayMode="AllErrorsFixed" AutoUpdate="true" /> <asp:Label ID="Label3" runat="server" Text="Thanks for fixing the errors" ForeColor="Maroon"></asp:Label><br/><br/> <h2>RelatedControlDisplayMode="NoErrorsShown"</h2> <des:ValidationSummary ID="ValidationSummary4" runat="server" RelatedControlID="Label4" RelatedControlDisplayMode="NoErrorsShown" /> <asp:Label ID="Label4" runat="server" Text="No errors to report" ForeColor="#C0C000"></asp:Label><br/>

Return to the menu   Select another DES Module