How to set automatically focus on ASP.NET controls when validation fails ? August 13, 2010Posted by Abhijit Jana in ASP.NET, General, Tips and Tricks.
Tags: Beginners, How To, Set Focus Automatically, validation control
If you are using ASP.NET Validation Control then you can use “SetFocusOnError” properties to automatically focus the control if validation fails. This will help the end user to identify the control easily.
To set focus automatically you have to set SetFocusOnError=”True”. 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.
Now in such case where multiple validation fails at same time then first validation will get the focus.
Hope this will help you !