Getting the name or ID of the User Name TextBox fr

2019-09-10 02:31发布

问题:

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.

回答1:

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();