How to set automatically focus on ASP.NET controls when validation fails ?

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.

SetFocus

Now in such case where multiple validation fails at same time then first validation will get the focus.

Hope this will help you !

Cheers !

AJ
Shout it

Advertisements

Written by Abhijit Jana

Technology Leader, Technical Strategist, Solution Architect, Development Consultant and a Trusted Technology Advisor with more than 11.5 years of experience in the IT industry with expertise in Development, Architecting, Engineering, Consulting, and Services Delivery. I am a former Microsoft MVP, Author of "Kinect for Windows SDK Programming Guide" and "HoloLens BluePrints" books and founder of The Daily .NET Tips . To know more about me visit "About Me" page.

4 comments

  1. Pingback: DotNetShoutout

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s