I read the article from
aspnet.4guysfromrolla.com/.../090902-1.2.aspx.I
made a small test
To focus on the First text Boox of the 3 called the
Key on Bodyonload of th ePage.But it failed to work
I think I am going wrong somewhere. can you
help
me.
The Test.aspx
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Focus4guys.aspx.vb"
Inherits="WebApplication1.Focus4guys"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>Focus4guys</title>
<meta name="GENERATOR"
content="Microsoft Visual
Studio.NET 7.0">
<meta name="CODE_LANGUAGE"
content="Visual Basic
7.0">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout"
onload=focus()>
<form id="Form1" method="post"
runat="server">
<input type="text" name="txtr">
<asp:TextBox id="TextBox1"
style="Z-INDEX: 101;
LEFT: 42px; POSITION: absolute; TOP: 8px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox3"
style="Z-INDEX: 103;
LEFT: 44px; POSITION: absolute; TOP: 95px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2"
style="Z-INDEX: 102;
LEFT: 44px; POSITION: absolute; TOP: 51px"
runat="server"></asp:TextBox>
</form>
</body>
</HTML>
The Test.aspx.vb
Public Class Focus4guys
Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As
System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As
System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox3 As
System.Web.UI.WebControls.TextBox
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private
Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by
the
Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
RegisterStartupScript("focus", "<script
language=""JavaScript"">" & vbCrLf & _
vbTab & "Form1.TextBox1.focus();" & _
vbCrLf & vbTab & "Form1.TextBox1.select();"
&
_
vbCrLf & "<" & "/script>")
End Sub
End Class