Return to the menu   Select another DES Module

Demonstrates moving the focus to the data entry control to call attention to errors

Add a PageManager control to the page. Then use these properties to establish focus:

  • FocusOnChange - Set the focus to the field after a change is made when there is a validation error. When true, focus is set on the field.
  • FocusOnSubmit – Set focus to the first field that generates a validation error when the page is submitted. When true, focus is set on the field.
  • FocusAfterAlert – Set focus to a field with an error after the alert is displayed when using the ErrorFormatters that display alerts. Supported by “Image with Alert” (AlertImageErrorFormatter) and “HyperLink with Alert” (HyperLinkErrorFormatter). When true, focus is set to the field after the alert is dismissed.

The ValidationSummary control also can set focus to fields with errors when you set HyperLinkToFields to true.


Controls

To show an error, click the button for FocusOnSubmit to set focus. The type 'abc' into the textbox and tab off for FocusOnChange to set focus.
The ValidationSummary also has its HyperLinkToFields property set to true, so click on its error messages.

TextBox1:
TextBox2:


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> To show an error, click the button for <span class="PropertyName">FocusOnSubmit</span> to set focus. The type 'abc' into the textbox and tab off for <span class="PropertyName">FocusOnChange</span> to set focus.<br/> The ValidationSummary also has its <a href="../../ValidationSummary/DisplayMode.aspx#HyperLinkToFields" class="PropertyName">HyperLinkToFields</a> property set to true, so click on its error messages.<br/> <br/> <des:PageManager ID="PageManager1" runat="server" FocusOnChange="True" FocusOnSubmit="True" /> TextBox1: <asp:TextBox ID="TextBox1" runat="server" /> <des:RequiredTextValidator ID="RequiredTextValidator1" runat="server" ControlIDToEvaluate="TextBox1" ErrorMessage="Required" SummaryErrorMessage="TextBox1 requires a value" > <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic" /> </ErrorFormatterContainer> </des:RequiredTextValidator> <des:DataTypeCheckValidator ID="DTC1" runat="server" ControlIDToEvaluate="TextBox1" DataType="Integer" ErrorMessage="Illegal format. Only digits are allowed." SummaryErrorMessage="TextBox1 requires an integer" /> <br/> TextBox2: <asp:TextBox ID="TextBox2" runat="server" /> <des:RequiredTextValidator ID="RequiredTextValidator2" runat="server" ControlIDToEvaluate="TextBox2" ErrorMessage="Required" SummaryErrorMessage="TextBox2 requires a value" > </des:RequiredTextValidator> <br/> <des:Button ID="Button1" runat="server" Text="Submit" /> <br/> <des:ValidationSummary ID="ValidationSummary1" runat="server" HyperLinkToFields="true" HeaderText="Please fix these errors:" />

Return to the menu   Select another DES Module