views:

62

answers:

2

I have an ASP.net page with a RegexValidator. The RegexValidator successfully displays my validation error text when a user types a value out of range and navigates (tabs) off of the control. At that point, it doesn't set the focus to that control, even though I have SetFocusOnError="true".

The focus does appear to be set when I click a button on that page.

Is focus supposed to be set as soon as the javascript detects on issue?

A: 

Is your RegEx validator inside of a naming container? If so, you'll need to do a little hacking.

Read this for some assistance and for this instance.

TheGeekYouNeed
A: 

The focus will return to the control when you attempt to submit the form. By default EnableClientScript is enabled, which performs client-side validation so no, there won't be a postback if validation fails and the browser is able to perform client-side validation.

From MSDN:

Use the EnableClientScript property to specify whether client-side validation is enabled.

Validation controls always perform validation on the server. They also have complete client-side implementation that allows DHTML-supported browsers (such as Microsoft Internet Explorer 4.0 and later) to perform validation on the client. Client-side validation enhances the validation process by checking user input before it is sent to the server. This allows errors to be detected on the client before the form is submitted, avoiding the round trip of information necessary for server-side validation.

By default, this value is set to true, which enables client-side validation if the browser supports it.

If you want immediate feedback from the validation control when the user tabs off of it, you can set its ErrorMessage property and set its Display property to either Dynamic or Static.

Ahmad Mageed