Search code examples
asp.netvb.netlogin-controlsetfocusloginview

Getting the name or ID of the User Name TextBox from an ASP.Net Login Control


In this ASP.Net Login Control can you tell me what ID or Name ASP.Net gives the User Name TextBox?

<asp:LoginView 
    ID="loginViewMain" 
    runat="server">

    <LoggedInTemplate>
        <asp:LoginName 
            ID="loginName" 
            runat="server"
            FormatString="Hello, {0}!<br/><br/> You have successfully<br/> logged onto the staff site." />

        <br/>
        <br/>

        (<asp:LoginStatus ID="loginStatus" runat="server" />)

        <br/>
        <br/>

    </LoggedInTemplate>

    <AnonymousTemplate>
        <asp:LoginStatus 
            ID="loginStatus" 
            runat="server" />
    </AnonymousTemplate>
</asp:LoginView>

I would like to set focus on the User Name TextBox once I know what ASP.Net names it from inside a code-behind file.


Solution

  • If I understand your question correctly, are you look for this?

    var loginName = (LoginName)loginViewMain.FindControl("loginName");
    

    Login Control

    var usernameTextBox = (TextBox)LoginUser.FindControl("UserName");
    userNameTextBox.Focus();