in

ASP.NET Weblogs

This Blog

Syndication

Sponsors

News


Follow HosamKamel on Twitter

Hosam Kamel's Blog

SetFocusOnError property

One of the newer features in ASP.NET 2.0 which required more JavaScript code injection in the previous ASP.NET versions is to set focus on a certain server control on page load

this feature is now supported in ASP.NET 2.0 You can use the Page.SetFocus method to pass the ID of a control that should receive focus or you can call the Focus method on the control directly.

   1: Page.SetFocus("ControlID");

Also you can  set the DefaultFocus property of the Form element to the ID of a control that should receive focus when the page is first loaded

   1: <form id="formMain" runat="server" defaultfocus="control1">   

you can refer to the focus feature here http://quickstarts.asp.net/QuickStartv20/aspnet/doc/tipstricks/default.aspx#focusapi

This feature has a similar one for the validation controls you can use the validation control SetFocusOnError to whether focus is set to the control specified by the ControlToValidate property when validation fails.

   1: <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" SetFocusOnError="true"  Display="Dynamic">
   2: </asp:RequiredFieldValidator>
   3:                                       
Published Sep 12 2007, 08:42 AM by Hosam Kamel
Filed under:

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add