Getting the name or ID of the User Name TextBox fr

2019-09-10 02:02发布

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条回答
欢心
2楼-- · 2019-09-10 02:55

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();
查看更多
登录 后发表回答