Search code examples
asp.net-membershipmembership

ASP.NET Membership - Login Control - TextBox Focus


I know this seems to be a very basic questions but I can't figure out how to give the textbox the focus on PageLoad.

Since this is a Login Control, I have no individual control over each textbox thru code the way I am used to it.

Does anyone happen to know how to give focus to the control please.

Steve


Solution

  • Adjust this to fit your requirments...

    protected void Page_Load(object sender, EventArgs e)
    {
        string focus = "document.getElementById('" + Login1.ClientID + "_UserName').focus();";
        // the following assumes that your login page's type is 'Login' 
        // e.g. public partial class Login : Page ....
        ClientScript.RegisterStartupScript(typeof(Login), "uidFocus", focus, true);
    }