我无法在 LoginView 内的登录控件中获取用户名文本框。它告诉我 UName “对象未设置为对象的实例”
Dim UName As TextBox = CType(LoginView1.FindControl("Login1").FindControl("UserName"), TextBox)
aspx
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<div class="logged">
<ul class="Logged">
<li><asp:LoginStatus ID="LoginStatus1" Font-Size="Small" LogoutPageUrl="http://NCOASouth.com" LogoutAction="Redirect" runat="server" /></li>
<li><asp:HyperLink ID="AdminLink" Visible="false" runat="server" NavigateUrl="~/Admin/Default.aspx" Text="Administration"></asp:HyperLink></li>
<li>Welcome, <asp:LoginName ID="LoginName1" runat="server" />!</li>
</ul>
</div>
</LoggedInTemplate>
<AnonymousTemplate>
<h2 class="title1">Officials Login</h2>
<br /><br /><br />
<asp:Login ID="Login1" DestinationPageUrl="http://NCOASouth.com/redirect.aspx"
CreateUserText="create new account" CreateUserUrl="~/Register.aspx" runat="server">
<LayoutTemplate>
<asp:TextBox ID="UserName" CssClass="textbox" runat="server" Width="195px" placeholder="Username"></asp:TextBox><br />
<asp:TextBox ID="Password" CssClass="textbox" runat="server" TextMode="Password" Width="195px" placeholder="Password"></asp:TextBox><br /><br />
<asp:Button ID="LoginButton" ValidationGroup="ctl00$Login1" CssClass="textbox" runat="server" CommandName="Login" Width="200px" Text="Sign In"/>
<br /><br />
<asp:HyperLink ID="createnewuser" runat="server" NavigateUrl="~/Register.aspx" Text="Register for Free" /><br />
<asp:HyperLink ID="forgotpassword" runat="server" NavigateUrl="~/forgotPassword.aspx" Text="Forgot Password" />
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
<br />
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="ctl00$Login1"></asp:RequiredFieldValidator>
<br />
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="ctl00$Login1"></asp:RequiredFieldValidator>
</LayoutTemplate>
</asp:Login>
</AnonymousTemplate>
</asp:LoginView>