Monday, November 15, 2004

VJs Tip Of The Day - November 15th 2004

Whidbey Days - Page.SetFocus method in ASP.Net

Many have struggled to do simple thing like setting up focus in ASP.Net page... Well not anymore... There is a simple method called Page.SetFocus in System.Web.UI.Page class in Whidbey...

Look at the signature of the method

public void SetFocus(Control) where the parameter is the control on which the focus needs to be set...

There is also an overload for the method available which takes string

public void SetFocus(String) where the parameter is the clientID of the control to set focus on...

There are two exceptions which this method can throw; they are ArgumentNullException in case the clientID or control to set focus on are null... The method also throws an InvalidOperationException in case the method is called after PreRender event of the page as after that the setting the focus is not possible...

Simple and Nice way isn't it... :-)

PS: November 19th will be temperory end of "Second Season" for tip of the day... I will be off for a one month long vacation and will catch up with you guys again in new year 2005 in the "Third Season"...

No comments: