Problem with focus for Login control and MasterPages

J

JeremyHolt

I am using a master page with an ImageButton. When I drop the Login control
in the <asp:content /> part of a new page, the LoginButton no longer receives
the focus when the user tabs out of the text boxes.

I've tried:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Me.Page.Form.DefaultButton = Me.Login1.FindControl("LoginButton").UniqueID
End Sub

but this only sets the focus on postback, not when the users tabs out of the
text box.

If I remove the ImageButton from the MasterPage, the loginButton receives
the focus correctly.

This is extremely irritating, because when the user presses the Enter key
after typing their password, they return to the login.aspx and the text boxes
are cleared.

Any suggestions please?

Thanks
Jeremy
 
J

JeremyHolt

I actually worked it out myself - but I'm sure there's a better way of doing
this!
Sub Page_Load
If Not Page.IsPostBack Then
Dim tbPassword As TextBox =
CType(Me.Login1.FindControl("Password"), TextBox)
Dim tbUserName As TextBox =
CType(Me.Login1.FindControl("UserName"), TextBox)
Dim LoginButtonID As String =
Me.Login1.FindControl("LoginButton").UniqueID
tbPassword.Attributes("onblur") = LoginButtonID & ".focus();"

tbPassword.Attributes("onkeydown") = _
"if ((event.which && event.which == 13) || (event.keyCode &&
event.keyCode == 13)) " & _
"{" & LoginButtonID & ".click();" & "return false;}
" & _
"else return true;"
End If
End Sub
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top