set focus (Javascript)

  • Thread starter Thread starter slinky
  • Start date Start date
S

slinky

I'm trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas? Thanks!

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">

<script language="JavaScript">
function doFocus(){

if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>

<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>
 
1. Where do you actually call the DoFocus()?
2. asp:TextBox seems to be not closed properly.

George.
 
I used this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtUserName.focus()
End Sub

But get this: 'focus' is not a member of
'System.Web.UI.webcontrols.TextBox'



You don't need JavaScript...Just put

txtUserName.focus();

in your page_load event.

Matthew Wells
(e-mail address removed)




I'm trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas?   Thanks!
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body  MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">
<script language="JavaScript">
function doFocus(){
if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>

<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>- Hide quoted text -

- Show quoted text -
 
Yes I'm using code-behind and the Intellisense did not list ".focus()"

That surprised me.  When you typed txtUserName., did you get intellisense
for .focus())?  I tested it before I repled to you.  I am using C#, but that
shouldn't make a difference.  Are you using a code-behind page?


I used this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        txtUserName.focus()
    End Sub

But get this: 'focus' is not a member of
'System.Web.UI.webcontrols.TextBox'

You don't need JavaScript...Just put

in your page_load event.
Matthew Wells
(e-mail address removed)
news:a7e73a0c-2f6a-439f-8610-e3e8709a5a1f@e53g2000hsa.googlegroups.com...
I'm trying to simply set the focus of "txtUserName" upon opening this
login form. I put in some Javascript but it is not working. Any
ideas? Thanks!
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb"
Inherits="Forsyth.HR_ReportingTool.UI.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" bgcolor="#6699ff"
background="file:///C:\Inetpub\wwwroot\HR_ReportingTool\vignette.gif">
<script language="JavaScript">
function doFocus(){
if(document.forms[0].txtUserName)document.forms[0].txtUserName.focus();
}
</script>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtUserName"
</asp:TextBox>
</form>
</body>
</HTML>- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
Sorry, should have noted that I'm using VB.net. But no Intellisense
is showing as a .Focus()
This is a weird one. Focus had always been so simple in VB 6.0

[top-posting corrected]
That surprised me.  When you typed txtUserName., did you get intellisense
for .focus())?  I tested it before I repled to you.  I am using C#, but
that shouldn't make a difference.  Are you using a code-behind page?

If you're using C#, .focus() certainly won't work nor will it show in
IntelliSense because C# is case-sensitive...

txtUserName.Focus() should work, though...
 
re:
!> This is a weird one. Focus had always been so simple in VB 6.0

It is, still, simple.

If you have a textbox named txtUserName in a VB aspx page,
when you go to the code-behind page and create a Sub Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

and then type txtUsername inside it, *and place a dot (.) after that*,
you should get a dropdown which includes Focus as one of the options.

The process is the same when you use inline code:

You create :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub

....and when you write, or select, txtUsername.

you'll get a dropdown which includes Focus as one of the options.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
Sorry, should have noted that I'm using VB.net. But no Intellisense
is showing as a .Focus()
This is a weird one. Focus had always been so simple in VB 6.0

[top-posting corrected]
That surprised me. When you typed txtUserName., did you get intellisense
for .focus())? I tested it before I repled to you. I am using C#, but
that shouldn't make a difference. Are you using a code-behind page?

If you're using C#, .focus() certainly won't work nor will it show in
IntelliSense because C# is case-sensitive...

txtUserName.Focus() should work, though...
 
I did exactly that, and still no Focus as a choice or accepted
keyword:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
txtUserName.
End Sub

I double-checked the spelling, etc.


re:
!> This is a weird one. Focus had always been so simple in VB 6.0

It is, still, simple.

If you have a textbox named txtUserName in a VB aspx page,
when you go to the code-behind page and create a Sub Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

and then type txtUsername inside it, *and place a dot (.) after that*,
you should get a dropdown which includes Focus as one of the options.

The process is the same when you use inline code:

You create :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub

...and when you write, or select, txtUsername.

you'll get a dropdown which includes Focus as one of the options.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/

Sorry, should have noted that I'm using VB.net.   But no Intellisense
is showing as a .Focus()
This is a weird one. Focus had always been so simple in VB 6.0


[top-posting corrected]
That surprised me. When you typed txtUserName., did you get intellisense
for .focus())? I tested it before I repled to you. I am using C#, but
that shouldn't make a difference. Are you using a code-behind page?
If you're using C#, .focus() certainly won't work nor will it show in
IntelliSense because C# is case-sensitive...
txtUserName.Focus() should work, though...

- Show quoted text -
 
re:
!> I did exactly that, and still no Focus as a choice or accepted keyword:

That's odd.

I just checked with both VS 2005 and VS 2008
....and I get Intellisense for Focus with both.


1. Which version of VS are you using ?

2. Do you actually have a textbox named txtUserName ?

I first tested with the standard "TextBox1" ID suggested by the IDE,
and then created a texbox with the ID "txtUserName",
and got the Intellisense dropdown with the Focus option for both.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
I did exactly that, and still no Focus as a choice or accepted keyword:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtUserName.
End Sub

I double-checked the spelling, etc.


re:
!> This is a weird one. Focus had always been so simple in VB 6.0

It is, still, simple.

If you have a textbox named txtUserName in a VB aspx page,
when you go to the code-behind page and create a Sub Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

and then type txtUsername inside it, *and place a dot (.) after that*,
you should get a dropdown which includes Focus as one of the options.

The process is the same when you use inline code:

You create :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub

...and when you write, or select, txtUsername.

you'll get a dropdown which includes Focus as one of the options.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/

Sorry, should have noted that I'm using VB.net. But no Intellisense
is showing as a .Focus()
This is a weird one. Focus had always been so simple in VB 6.0


[top-posting corrected]
That surprised me. When you typed txtUserName., did you get intellisense
for .focus())? I tested it before I repled to you. I am using C#, but
that shouldn't make a difference. Are you using a code-behind page?
If you're using C#, .focus() certainly won't work nor will it show in
IntelliSense because C# is case-sensitive...
txtUserName.Focus() should work, though...

- Show quoted text -
 
VS 2003 Version 7.1.6030
.net framework 1.1 Version 1.1.4322 SP1

yes definitely have a textbox on my .aspx named txtUserName

re:
!> I did exactly that, and still no Focus as a choice or accepted keyword:

That's odd.

I just checked with both VS 2005 and VS 2008
...and I get Intellisense for Focus with both.

1. Which version of VS are you using ?

2. Do you actually have a textbox named txtUserName ?

I first tested with the standard "TextBox1" ID suggested by the IDE,
and then created a texbox with the ID "txtUserName",
and got the Intellisense dropdown with the Focus option for both.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/

I did exactly that, and still no Focus as a choice or accepted keyword:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
 txtUserName.
End Sub

I double-checked the spelling, etc.

re:
!> This is a weird one. Focus had always been so simple in VB 6.0
It is, still, simple.
If you have a textbox named txtUserName in a VB aspx page,
when you go to the code-behind page and create a Sub Page_Load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
and then type txtUsername inside it, *and place a dot (.) after that*,
you should get a dropdown which includes Focus as one of the options.
The process is the same when you use inline code:
You create :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
...and when you write, or select, txtUsername.
you'll get a dropdown which includes Focus as one of the options.
Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
======================================"slinky" <[email protected]> wrote in message
Sorry, should have noted that I'm using VB.net. But no Intellisense
is showing as a .Focus()
This is a weird one. Focus had always been so simple in VB 6.0
[top-posting corrected]
That surprised me. When you typed txtUserName., did you get intellisense
for .focus())? I tested it before I repled to you. I am using C#, but
that shouldn't make a difference. Are you using a code-behind page?
If you're using C#, .focus() certainly won't work nor will it show in
IntelliSense because C# is case-sensitive...
txtUserName.Focus() should work, though...
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
Back
Top