A
ad
I use a LoginView to authenticate user.
Can we set the focus in the UserName or Password of the LoginView?
Can we set the focus in the UserName or Password of the LoginView?
jnewquis said:I also had this page inside a master.page but this is what worked for me in the PreRender event ...
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
'Find the Login control inside the LoginView
Dim curLogin As System.Web.UI.WebControls.Login = CType(LoginView1.FindControl("Login1"), System.Web.UI.WebControls.Login)
'Then find the Username textbox control
Dim txtUsername As TextBox = CType(curLogin.FindControl("UserName"), TextBox)
'Now set the focus on it
txtUsername.Focus()
End Sub
jostar said:Thanks for the ideas in VB.
Here is a C# solution that workes for me.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(!User.Identity.IsAuthenticated)
{
Login lg = (Login)LoginView1.FindControl("Login1");
TextBox tb = (TextBox)lg.FindControl("UserName");
SetFocus(tb);
}
}
}
BTW notice that tb does not have double quotes around it in the SetFocus (tb). I was pulling my hair out following another thread that had quotes around the control string inside the SetFocus method. If I can find that post again, I'll put in a correction there too!
John
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.