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

久未见 提交于 2019-12-12 02:24:14

问题


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


来源:https://stackoverflow.com/questions/15117980/getting-the-name-or-id-of-the-user-name-textbox-from-an-asp-net-login-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!