When my page is shown, I want the first textfield to have the focus. I found somewhere a solution for this :
in the page_load I call a routine :
SetFocusControl(Page, Me.txtNr.ID.ToString)
... and the SetFocusControl-routine :
Public Sub SetFocusControl(ByRef Pagina As System.Web.UI.Page,
ByVal ControlName As String)
' character 34 = "
Dim script As String = _
"<script language=" + Chr(34) + "javascript" + Chr(34) _
+ ">" + _
" var control = document.getElementById(" + Chr(34) + _
ControlName + Chr(34) + ");" & _
" if( control != null ){control.select();}" & _
"</script>"
Pagina.RegisterStartupScript("Focus", script)
End Sub
Now, all this works fine (field gets the focus and the whole contents is selected), but when I push TAB the focus goes to the Address-bar instead of the second textfield ??
Any idea why ? Are is there another 'better' solution to do this ?You need to set the tabindex property for each control on the page.
DJ
I don't know if this works, but I wonder why I haven't any problem when I go manualy (with mouse-click) to this first field and push on the TAB (this results correctly to the next field) ? So why not the first time ?
PS : all tabindexes are set to 0 for the moment.
In IE the address bar (unless otherwise specified) is the first to go to when you press tab. So I'm presuming because you haven't set tabindexes it will revert to the address bar again. Give it a try changing the tabindexes - I'm sure thats the problem.
DJ
Sorry, it's a long time ago but I become a father meanwhile...
I fill in the tabindex (login, password, persistent cookie and submit button), but it still goes to the address bar :cry:
Here's the HTML :
<body>
<form id="Form1" method="post" runat="server">
<H1 align="left"><FONT size="7"><IMG src="http://pics.10026.com/?src=Images/PROFORTRA.jpg"></FONT></H1>
<H1 align="left"><FONT size="7">Welcome</FONT></H1>
<H2 align="left">To access this site you have to log on first.</H2>
<P>
<TABLE class="TABLE" id="tlbLogin" style="WIDTH: 560px; HEIGHT: 130px" cellSpacing="1"
cellPadding="1" width="560" border="0">
<TR>
<TD style="WIDTH: 91px">Username
</TD>
<TD><asp:textbox id="UserName" tabIndex="1" runat="server" BackColor="LightGray" Width="160px"></asp:textbox> <asp:requiredfieldvalidator id="reqUserName" runat="server" ErrorMessage="Username is required !" ControlToValidate="UserName"></asp:requiredfieldvalidator></TD>
</TR>
<TR>
<TD style="WIDTH: 91px">Password</TD>
<TD><asp:textbox id="PassWord" tabIndex="2" runat="server" BackColor="LightGray" Width="160px" TextMode="Password"></asp:textbox> <asp:requiredfieldvalidator id="reqPassWord" runat="server" ErrorMessage="Password is required !" ControlToValidate="PassWord"></asp:requiredfieldvalidator></TD>
</TR>
<tr>
<td>Persistent Cookie</td>
<td><ASP:CHECKBOX id="Persist" tabIndex="3" runat="server"></ASP:CHECKBOX></td>
</tr>
</TABLE>
</P>
<P><asp:label id="lblFout" runat="server" ForeColor="Red" Font-Size="Medium"></asp:label></P>
<P><asp:button id="btnLogOn" tabIndex="4" runat="server" Text="Log On"></asp:button></P>
</form>
</body>
First off - congratulations!
Secondly - does this happen in all browsers?
DJ
Thx !
Since I'm just starting, I just try it on my notebook with IE (version 6.0.2900.2180).
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment