使用这个 ASP.Net LoginView,我们想在网页加载时将焦点设置在用户名文本框上:
<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>
这是我们试图用来关注用户名文本框的代码隐藏:
Private Sub loginViewMain_Load(sender As Object, e As EventArgs) Handles loginViewMain.Load
Dim objContentPlaceHolder As ContentPlaceHolder
Dim objLoginView As LoginView
Dim objUserName As TextBox
objContentPlaceHolder = CType(Me.FindControl("ContentPlaceHolderBody"), ContentPlaceHolder)
If Not objContentPlaceHolder Is Nothing Then
objLoginView = CType(objContentPlaceHolder.FindControl("loginViewMain"), LoginView)
If Not objLoginView Is Nothing Then
objUserName = objLoginView.FindControl("UserName")
objUserName.Focus()
End If
End If
End Sub
执行确实进入了这个 If 结构:
If Not objLoginView Is Nothing Then
你能告诉我我还需要在这个编码的 If 结构中添加什么来获取用户名文本框吗?