Automatically focus on ASP.NET controls when validation fails

For an ASP.NET Validation Control you have a chance to use “SetFocusOnError” properties to automatically focus the control if validation fails. This will help the end user to identify the control easily.

By default it’s false. SetFocusOnError of a validation control is associated with “ControlToValidate” properties. If the validation fails, focus will automatically move to the control which is specified in ControlToValidate.

Example:

TextBox ID=”ddlFyear” runat=”server” Width=”170px” MaxLength=”4″>
RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server”
ControlToValidate=”ddlFyear” ErrorMessage=”Enter Financial Year”
ValidationGroup=”a”
SetFocusOnError=”True”>*
</asp:RequiredFieldValidator>

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