Web Form Default Control Focus using Master Page

It’s straight-forward to set Default Focus with simple Web Form. Just set “defaultfocus” property to “ControlName” in “form” tag to get Default Control Focus in Web Form.


form id="form1" runat="server" defaultfocus="studentCodeTextBox"


However, it can not be done this way while using Master Page. Here, it has to be set at Page Load Event.


protected void Page_Load(object sender, EventArgs e)
{        
  Page.Form.DefaultFocus = userNameTextBox.ClientID;
}


Alternatively, You can get it done in the following way.


protected void Page_Load(object sender, EventArgs e)
{        
  userNameTextBox.Focus();
}

Thanks
A Rahim Khan

Advertisements
  1. No trackbacks yet.

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: