Set focus to textbox in ASP.NET Login control on page load
When you see the page that contains the login form, by default, the focus is not set to no control.
If you want to bring focus to the first form's textbox to login e.g. Username, when the page is displayed, you can follow different ways:
1) First, it brings the focus to the control TextBoxUsername
using System;
using System.Web.UI.WebControls;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SetFocus(LoginForm.FindControl("TextBoxUsername"));
}
}
2) Second chance brings the focus to the first control that you see in LoginForm
using System;
using System.Web.UI.WebControls;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LoginForm.Focus();
}
}
Simple right?