Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > set focus (Javascript)

Reply
Thread Tools

set focus (Javascript)

 
 
slinky
Guest
Posts: n/a
 
      06-04-2008
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>
 
Reply With Quote
 
 
 
 
George Ter-Saakov
Guest
Posts: n/a
 
      06-04-2008
1. Where do you actually call the DoFocus()?
2. asp:TextBox seems to be not closed properly.

George.

"slinky" <(E-Mail Removed)> wrote in message
news:(E-Mail 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>



 
Reply With Quote
 
 
 
 
slinky
Guest
Posts: n/a
 
      06-05-2008
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'



On Jun 4, 4:08*pm, "Matthew Wells" <(E-Mail Removed)>
wrote:
> You don't need JavaScript...Just put
>
> txtUserName.focus();
>
> in your page_load event.
>
> Matthew Wells
> (E-Mail Removed)
>
> "slinky" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail 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 -


 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-05-2008
Yes I'm using code-behind and the Intellisense did not list ".focus()"

On Jun 5, 9:23*am, "Matthew Wells" <(E-Mail Removed)>
wrote:
> 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?
>
> "slinky" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> 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'
>
> On Jun 4, 4:08 pm, "Matthew Wells" <(E-Mail Removed)>
> wrote:
>
>
>
> > You don't need JavaScript...Just put

>
> > txtUserName.focus();

>
> > in your page_load event.

>
> > Matthew Wells
> > (E-Mail Removed)

>
> > "slinky" <(E-Mail Removed)> wrote in message

>
> >news:(E-Mail 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 -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-05-2008
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

On Jun 5, 11:46*am, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "Matthew Wells" <(E-Mail Removed)> wrote in message
>
> news(E-Mail Removed). ..
>
> [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...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      06-05-2008
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/
======================================
"slinky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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

On Jun 5, 11:46 am, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "Matthew Wells" <(E-Mail Removed)> wrote in message
>
> news(E-Mail Removed). ..
>
> [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...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net




 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-05-2008
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.


On Jun 5, 12:33*pm, "Juan T. Llibre" <(E-Mail Removed)>
wrote:
> 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/
> ======================================"slinky" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> 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
>
> On Jun 5, 11:46 am, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
>
>
>
> > "Matthew Wells" <(E-Mail Removed)> wrote in message

>
> >news(E-Mail Removed) ...

>
> > [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...

>
> > --
> > Mark Rae
> > ASP.NET MVPhttp://www.markrae.net- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      06-05-2008
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/
======================================
"slinky" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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.


On Jun 5, 12:33 pm, "Juan T. Llibre" <(E-Mail Removed)>
wrote:
> 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/
> ======================================"slinky" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> 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
>
> On Jun 5, 11:46 am, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
>
>
>
> > "Matthew Wells" <(E-Mail Removed)> wrote in message

>
> >news(E-Mail Removed) ...

>
> > [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...

>
> > --
> > Mark Rae
> > ASP.NET MVPhttp://www.markrae.net- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-05-2008
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

On Jun 5, 1:38*pm, "Juan T. Llibre" <(E-Mail Removed)> wrote:
> 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/
> ======================================"slinky" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> 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.
>
> On Jun 5, 12:33 pm, "Juan T. Llibre" <(E-Mail Removed)>
> wrote:
>
>
>
> > 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/
> > ======================================"slinky" <(E-Mail Removed)> wrote in message

>
> >news:(E-Mail Removed)...
> > 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

>
> > On Jun 5, 11:46 am, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:

>
> > > "Matthew Wells" <(E-Mail Removed)> wrote in message

>
> > >news(E-Mail Removed) ...

>
> > > [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...

>
> > > --
> > > Mark Rae
> > > ASP.NET MVPhttp://www.markrae.net-Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
Why does putting focus on textbox also set focus to submit jw56578@gmail.com Javascript 2 06-06-2005 08:20 PM
Pan Focus vs Auto Focus JethroUK© Digital Photography 2 08-11-2004 06:26 PM
any manual focus cameras easy to focus? Catherine Jo Morgan Digital Photography 6 11-05-2003 06:36 PM
Unable to set focus to textfield in a applet if browser is set to Sun JRE 1.4 Manav Java 0 10-15-2003 03:42 PM



Advertisments