|
 |
aspx thread: <input> box focus
Message #1 by "J Donahue" <jdonahue@f...> on Thu, 25 Jul 2002 20:24:28
|
|
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #2 by "David Adames" <david@p...> on Thu, 25 Jul 2002 15:22:27 -0400
|
|
Once you have done your city and state fill routine can't you setfocus on
the control you want?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #3 by "J Donahue" <jdonahue@f...> on Thu, 25 Jul 2002 20:39:32
|
|
I'm using VB.NET and apparently it doesn't support setfocus. I simply
tried <myvar>.setfocus and it errors. I looked it up and it said
setfocus was replaced by activate but <myvar>.activate isn't valid either.
> Once you have done your city and state fill routine can't you setfocus
on
the control you want?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #4 by "David Adames" <david@p...> on Thu, 25 Jul 2002 15:43:29 -0400
|
|
Per one of my VB.NET books setfocus has been replaced with focus. Does
focus pop up with intellisense?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:40 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
I'm using VB.NET and apparently it doesn't support setfocus. I simply
tried <myvar>.setfocus and it errors. I looked it up and it said
setfocus was replaced by activate but <myvar>.activate isn't valid either.
> Once you have done your city and state fill routine can't you setfocus
on
the control you want?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #5 by "J Donahue" <jdonahue@f...> on Thu, 25 Jul 2002 23:12:03
|
|
Nope...intellisense doesn't show focus either.
> Per one of my VB.NET books setfocus has been replaced with focus. Does
focus pop up with intellisense?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:40 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
I'm using VB.NET and apparently it doesn't support setfocus. I simply
tried <myvar>.setfocus and it errors. I looked it up and it said
setfocus was replaced by activate but <myvar>.activate isn't valid either.
> Once you have done your city and state fill routine can't you setfocus
on
the control you want?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #6 by "David Adames" <david@p...> on Thu, 25 Jul 2002 19:51:32 -0400
|
|
I truly am befuddled as I've seen a few references to the new focus method
which I also can not bring up in Intellisense. MSDN lists vb6 to vb.net
changes and it also says Setfocus is now focus.
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 11:12 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
Nope...intellisense doesn't show focus either.
> Per one of my VB.NET books setfocus has been replaced with focus. Does
focus pop up with intellisense?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:40 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
I'm using VB.NET and apparently it doesn't support setfocus. I simply
tried <myvar>.setfocus and it errors. I looked it up and it said
setfocus was replaced by activate but <myvar>.activate isn't valid either.
> Once you have done your city and state fill routine can't you setfocus
on
the control you want?
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #7 by "David Adames" <david@p...> on Thu, 25 Jul 2002 20:02:48 -0400
|
|
I realize now that I have been seeing the focus method for Winforms not for
Webforms. More research...
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #8 by "David Adames" <david@p...> on Thu, 25 Jul 2002 20:10:49 -0400
|
|
This should do it
[VISUAL BASIC]
' <summary>
' SetFocus
' Set Focus to a web control
' </summary>
' <param name="System.Web.UI.Control ctrl"></param>
Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT language='javascript'>document.getElementById('"
& ctrl.ID & "').focus() </SCRIPT>"
RegisterStartupScript("focus", s)
End Sub
Calling SetFocus( )
Me.SetFocus(Me.TextBox1)
From...
http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
-----Original Message-----
From: David Adames [mailto:david@p...]
Sent: Thursday, July 25, 2002 8:03 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
I realize now that I have been seeing the focus method for Winforms not for
Webforms. More research...
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #9 by "J Donahue" <jdonahue@f...> on Fri, 26 Jul 2002 17:22:29
|
|
I imported Systems.Web.UI.Page, then I have the following:
HTML code:
<asp:textbox ID="mybox" Runat="server" Width="20"></asp:textbox>
VB NET code:
Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT
language='javascript'>document.getElementById('" & ctrl.ID & "').focus()
</SCRIPT>"
Page.RegisterStartupScript("focus", s)
End Sub
Now when I run the page and go to the Zip code <input> box, it calls a
server side routine and within that routine I call the SetFocus as:
Me.SetFocus(Me.mybox)
It causes a javascript error that says 'document.getElementByID(...)" is
null or not an object.
I looked at the html after entering something in the zip code <input> box
and I see the following inserted at the bottom of the page just above the
</form>
<SCRIPT language='javascript'>document.getElementById('mybox').focus()
</SCRIPT>
I know I'm close but I just don't know why I'm getting the "is null or
not an object error".
And....I want to say thanks to David for all his excellent help!!!!!
-Jim
> This should do it
[VISUAL BASIC]
' <summary>
' SetFocus
' Set Focus to a web control
' </summary>
' <param name="System.Web.UI.Control ctrl"></param>
Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String = "<SCRIPT
language='javascript'>document.getElementById('"
& ctrl.ID & "').focus() </SCRIPT>"
RegisterStartupScript("focus", s)
End Sub
Calling SetFocus( )
Me.SetFocus(Me.TextBox1)
From...
http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
-----Original Message-----
From: David Adames [mailto:david@p...]
Sent: Thursday, July 25, 2002 8:03 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
I realize now that I have been seeing the focus method for Winforms not
for
Webforms. More research...
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Thursday, July 25, 2002 8:24 PM
To: ASP+
Subject: [aspx] <input> box focus
I know Javascript uses focus to target an <input> box. Is there a way to
target a certain <input> box from within a NET server control??
I have a form and have disabled the enterkey, replacing it with the tab
key. The zip code field checks the user entry and if found, fills in the
city, state. The problem is, once it does that the cursor is no longer
on the form. I simply want to target the next <input> box
thanks!!
Message #10 by "Joe Fawcett" <joefawcett@h...> on Fri, 26 Jul 2002 17:22:29 +0100
|
|
getElementById (with a small 'd').
Joe
>From: "J Donahue" <jdonahue@f...>
>Reply-To: "ASP+" <aspx@p...>
>To: "ASP+" <aspx@p...>
>Subject: [aspx] RE: <input> box focus
>Date: Fri, 26 Jul 2002 17:22:29
>
>I imported Systems.Web.UI.Page, then I have the following:
>
>HTML code:
><asp:textbox ID="mybox" Runat="server" Width="20"></asp:textbox>
>
>VB NET code:
>Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
> Dim s As String = "<SCRIPT
>language='javascript'>document.getElementById('" & ctrl.ID & "').focus()
></SCRIPT>"
> Page.RegisterStartupScript("focus", s)
>End Sub
>
>Now when I run the page and go to the Zip code <input> box, it calls a
>server side routine and within that routine I call the SetFocus as:
>Me.SetFocus(Me.mybox)
>
>It causes a javascript error that says 'document.getElementByID(...)" is
>null or not an object.
>
>I looked at the html after entering something in the zip code <input> box
>and I see the following inserted at the bottom of the page just above the
></form>
><SCRIPT language='javascript'>document.getElementById('mybox').focus()
></SCRIPT>
>
>I know I'm close but I just don't know why I'm getting the "is null or
>not an object error".
>
>And....I want to say thanks to David for all his excellent help!!!!!
>
>-Jim
>
> > This should do it
>[VISUAL BASIC]
>
>' <summary>
>' SetFocus
>' Set Focus to a web control
>' </summary>
>' <param name="System.Web.UI.Control ctrl"></param>
>
>Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
> Dim s As String = "<SCRIPT
>language='javascript'>document.getElementById('"
> & ctrl.ID & "').focus() </SCRIPT>"
> RegisterStartupScript("focus", s)
>End Sub
>
>Calling SetFocus( )
> Me.SetFocus(Me.TextBox1)
>
>From...
>http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
>
>
>
>
>-----Original Message-----
>From: David Adames [mailto:david@p...]
>Sent: Thursday, July 25, 2002 8:03 PM
>To: ASP+
>Subject: [aspx] RE: <input> box focus
>
>
>I realize now that I have been seeing the focus method for Winforms not
>for
>Webforms. More research...
>
>-----Original Message-----
>From: J Donahue [mailto:jdonahue@f...]
>Sent: Thursday, July 25, 2002 8:24 PM
>To: ASP+
>Subject: [aspx] <input> box focus
>
>
>I know Javascript uses focus to target an <input> box. Is there a way to
>target a certain <input> box from within a NET server control??
>I have a form and have disabled the enterkey, replacing it with the tab
>key. The zip code field checks the user entry and if found, fills in the
>city, state. The problem is, once it does that the cursor is no longer
>on the form. I simply want to target the next <input> box
>thanks!!
>
>
>
_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
Message #11 by "J Donahue" <jdonahue@f...> on Fri, 26 Jul 2002 18:01:51
|
|
Sorry for my typing....getElementById does have a small 'd'
> getElementById (with a small 'd').
Joe
>From: "J Donahue" <jdonahue@f...>
>Reply-To: "ASP+" <aspx@p...>
>To: "ASP+" <aspx@p...>
>Subject: [aspx] RE: <input> box focus
>Date: Fri, 26 Jul 2002 17:22:29
>
>I imported Systems.Web.UI.Page, then I have the following:
>
>HTML code:
><asp:textbox ID="mybox" Runat="server" Width="20"></asp:textbox>
>
>VB NET code:
>Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
> Dim s As String = "<SCRIPT
>language='javascript'>document.getElementById('" & ctrl.ID & "').focus()
></SCRIPT>"
> Page.RegisterStartupScript("focus", s)
>End Sub
>
>Now when I run the page and go to the Zip code <input> box, it calls a
>server side routine and within that routine I call the SetFocus as:
>Me.SetFocus(Me.mybox)
>
>It causes a javascript error that says 'document.getElementByID(...)" is
>null or not an object.
>
>I looked at the html after entering something in the zip code <input> box
>and I see the following inserted at the bottom of the page just above the
></form>
><SCRIPT language='javascript'>document.getElementById('mybox').focus()
></SCRIPT>
>
>I know I'm close but I just don't know why I'm getting the "is null or
>not an object error".
>
>And....I want to say thanks to David for all his excellent help!!!!!
>
>-Jim
>
> > This should do it
>[VISUAL BASIC]
>
>' <summary>
>' SetFocus
>' Set Focus to a web control
>' </summary>
>' <param name="System.Web.UI.Control ctrl"></param>
>
>Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
> Dim s As String = "<SCRIPT
>language='javascript'>document.getElementById('"
> & ctrl.ID & "').focus() </SCRIPT>"
> RegisterStartupScript("focus", s)
>End Sub
>
>Calling SetFocus( )
> Me.SetFocus(Me.TextBox1)
>
>From...
>http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
>
>
>
>
>-----Original Message-----
>From: David Adames [mailto:david@p...]
>Sent: Thursday, July 25, 2002 8:03 PM
>To: ASP+
>Subject: [aspx] RE: <input> box focus
>
>
>I realize now that I have been seeing the focus method for Winforms not
>for
>Webforms. More research...
>
>-----Original Message-----
>From: J Donahue [mailto:jdonahue@f...]
>Sent: Thursday, July 25, 2002 8:24 PM
>To: ASP+
>Subject: [aspx] <input> box focus
>
>
>I know Javascript uses focus to target an <input> box. Is there a way to
>target a certain <input> box from within a NET server control??
>I have a form and have disabled the enterkey, replacing it with the tab
>key. The zip code field checks the user entry and if found, fills in the
>city, state. The problem is, once it does that the cursor is no longer
>on the form. I simply want to target the next <input> box
>thanks!!
>
>
>
_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail.
http://www.hotmail.com
Message #12 by "J Donahue" <jdonahue@f...> on Fri, 26 Jul 2002 19:08:33
|
|
Sheesh...I got it to work by changing parts of the <SCRIPT> as follows:
Dim s As String = "<SCRIPT language='javascript'>document.getElementById
('" & ctrl.ClientID & "').focus(); </script>
so I changed ctrl.ID to ctrl.ClientID and then I put a ; after the focus()
Thanks again everyone...and especially David!!!
Jim
>
>> From: "J Donahue" <jdonahue@f...>
>> Reply-To: "ASP+" <aspx@p...>
>> To: "ASP+" <aspx@p...>
>> Subject: [aspx] RE: <input> box focus
>> Date: Fri, 26 Jul 2002 17:22:29
>>
>> I imported Systems.Web.UI.Page, then I have the following:
>>
>> HTML code:
>> <asp:textbox ID="mybox" Runat="server" Width="20"></asp:textbox>
>>
>> VB NET code:
>> Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
>> Dim s As String = "<SCRIPT
>> language='javascript'>document.getElementById('" & ctrl.ID & "').focus
()
>> </SCRIPT>"
>> Page.RegisterStartupScript("focus", s)
>> End Sub
>>
>> Now when I run the page and go to the Zip code <input> box, it calls a
>> server side routine and within that routine I call the SetFocus as:
>> Me.SetFocus(Me.mybox)
>>
>> It causes a javascript error that says 'document.getElementByID(...)"
is
>> null or not an object.
>>
>> I looked at the html after entering something in the zip code <input>
box
>> and I see the following inserted at the bottom of the page just above
the
>> </form>
>> <SCRIPT language='javascript'>document.getElementById('mybox').focus()
>> </SCRIPT>
>>
>> I know I'm close but I just don't know why I'm getting the "is null or
>> not an object error".
>>
>> And....I want to say thanks to David for all his excellent help!!!!!
>>
>> -Jim
>>
>> > This should do it
>> [VISUAL BASIC]
>>
>> ' <summary>
>> ' SetFocus
>> ' Set Focus to a web control
>> ' </summary>
>> ' <param name="System.Web.UI.Control ctrl"></param>
>>
>> Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
>> Dim s As String = "<SCRIPT
>> language='javascript'>document.getElementById('"
>> & ctrl.ID & "').focus() </SCRIPT>"
>> RegisterStartupScript("focus", s)
>> End Sub
>>
>> Calling SetFocus( )
>> Me.SetFocus(Me.TextBox1)
>>
>> From...
>> http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
>>
>>
>>
>>
>> -----Original Message-----
>> From: David Adames [mailto:david@p...]
>> Sent: Thursday, July 25, 2002 8:03 PM
>> To: ASP+
>> Subject: [aspx] RE: <input> box focus
>>
>>
>> I realize now that I have been seeing the focus method for Winforms not
>> for
>> Webforms. More research...
>>
>> -----Original Message-----
>> From: J Donahue [mailto:jdonahue@f...]
>> Sent: Thursday, July 25, 2002 8:24 PM
>> To: ASP+
>> Subject: [aspx] <input> box focus
>>
>>
>> I know Javascript uses focus to target an <input> box. Is there a way
to
>> target a certain <input> box from within a NET server control??
>> I have a form and have disabled the enterkey, replacing it with the tab
>> key. The zip code field checks the user entry and if found, fills in
the
>> city, state. The problem is, once it does that the cursor is no longer
>> on the form. I simply want to target the next <input> box
>> thanks!!
>>
>>
>>
>
>
_> ________________________________________________________________
J> oin the world?s largest e-mail service with MSN Hotmail.
h> ttp://www.hotmail.com
Message #13 by "J Donahue" <jdonahue@f...> on Fri, 26 Jul 2002 20:02:28
|
|
Ouch! Now I have the server side focus working. It works great on aspx
pages with no controls or only one control. It doesn't work so well on
an aspx page with multiple controls.
I have such a page with multiple controls that I simply manipulate by
using the visibility element.
When the first control is made visible, I load the focus to set my cursor
to the first input box. It works great and puts the javascript code at
the bottom of the html.
Problem is, when I leave that control and load another, that old
javascript code remains when the new control page is loaded and I error
out because the original input box is not part of the new control.
Is there a way to get rid of that javascript put at the bottom of the
page via the "Page.RegisterStartupScript("focus", s)" before the new
control is loaded???
Thanks...Jim!!!
> Sheesh...I got it to work by changing parts of the <SCRIPT> as follows:
> Dim s As String = "<SCRIPT language='javascript'>document.getElementById
(> '" & ctrl.ClientID & "').focus(); </script>
> so I changed ctrl.ID to ctrl.ClientID and then I put a ; after the focus
()
> Thanks again everyone...and especially David!!!
> Jim
> >
>> > From: "J Donahue" <jdonahue@f...>
>> > Reply-To: "ASP+" <aspx@p...>
>> > To: "ASP+" <aspx@p...>
>> > Subject: [aspx] RE: <input> box focus
>> > Date: Fri, 26 Jul 2002 17:22:29
>> >
>> > I imported Systems.Web.UI.Page, then I have the following:
>> >
>> > HTML code:
>> > <asp:textbox ID="mybox" Runat="server" Width="20"></asp:textbox>
>> >
>> > VB NET code:
>> > Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
>> > Dim s As String = "<SCRIPT
>> > language='javascript'>document.getElementById('" & ctrl.ID
& "').focus
(> )
>> > </SCRIPT>"
>> > Page.RegisterStartupScript("focus", s)
>> > End Sub
>> >
>> > Now when I run the page and go to the Zip code <input> box, it calls
a
>> > server side routine and within that routine I call the SetFocus as:
>> > Me.SetFocus(Me.mybox)
>> >
>> > It causes a javascript error that says 'document.getElementByID
(...)"
i> s
>> > null or not an object.
>> >
>> > I looked at the html after entering something in the zip code
<input>
b> ox
>> > and I see the following inserted at the bottom of the page just
above
t> he
>> > </form>
>> > <SCRIPT language='javascript'>document.getElementById('mybox').focus
()
>> > </SCRIPT>
>> >
>> > I know I'm close but I just don't know why I'm getting the "is null
or
>> > not an object error".
>> >
>> > And....I want to say thanks to David for all his excellent help!!!!!
>> >
>> > -Jim
>> >
>> > > This should do it
>> > [VISUAL BASIC]
>> >
>> > ' <summary>
>> > ' SetFocus
>> > ' Set Focus to a web control
>> > ' </summary>
>> > ' <param name="System.Web.UI.Control ctrl"></param>
>> >
>> > Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
>> > Dim s As String = "<SCRIPT
>> > language='javascript'>document.getElementById('"
>> > & ctrl.ID & "').focus() </SCRIPT>"
>> > RegisterStartupScript("focus", s)
>> > End Sub
>> >
>> > Calling SetFocus( )
>> > Me.SetFocus(Me.TextBox1)
>> >
>> > From...
>> > http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
>> >
Message #14 by "David Adames" <david@p...> on Fri, 26 Jul 2002 16:27:28 -0400
|
|
Excellent! My pleasure to have found the code to get you started and thanks
for the correction.
David
-----Original Message-----
From: J Donahue [mailto:jdonahue@f...]
Sent: Friday, July 26, 2002 7:09 PM
To: ASP+
Subject: [aspx] RE: <input> box focus
Sheesh...I got it to work by changing parts of the <SCRIPT> as follows:
Dim s As String = "<SCRIPT language='javascript'>document.getElementById
('" & ctrl.ClientID & "').focus(); </script>
so I changed ctrl.ID to ctrl.ClientID and then I put a ; after the focus()
Thanks again everyone...and especially David!!!
Jim
>
>> From: "J Donahue" <jdonahue@f...>
>> Reply-To: "ASP+" <aspx@p...>
>> To: "ASP+" <aspx@p...>
>> Subject: [aspx] RE: <input> box focus
>> Date: Fri, 26 Jul 2002 17:22:29
>>
>> I imported Systems.Web.UI.Page, then I have the following:
>>
>> HTML code:
>> <asp:textbox ID="mybox" Runat="server" Width="20"></asp:textbox>
>>
>> VB NET code:
>> Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
>> Dim s As String = "<SCRIPT
>> language='javascript'>document.getElementById('" & ctrl.ID & "').focus
()
>> </SCRIPT>"
>> Page.RegisterStartupScript("focus", s)
>> End Sub
>>
>> Now when I run the page and go to the Zip code <input> box, it calls a
>> server side routine and within that routine I call the SetFocus as:
>> Me.SetFocus(Me.mybox)
>>
>> It causes a javascript error that says 'document.getElementByID(...)"
is
>> null or not an object.
>>
>> I looked at the html after entering something in the zip code <input>
box
>> and I see the following inserted at the bottom of the page just above
the
>> </form>
>> <SCRIPT language='javascript'>document.getElementById('mybox').focus()
>> </SCRIPT>
>>
>> I know I'm close but I just don't know why I'm getting the "is null or
>> not an object error".
>>
>> And....I want to say thanks to David for all his excellent help!!!!!
>>
>> -Jim
>>
>> > This should do it
>> [VISUAL BASIC]
>>
>> ' <summary>
>> ' SetFocus
>> ' Set Focus to a web control
>> ' </summary>
>> ' <param name="System.Web.UI.Control ctrl"></param>
>>
>> Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
>> Dim s As String = "<SCRIPT
>> language='javascript'>document.getElementById('"
>> & ctrl.ID & "').focus() </SCRIPT>"
>> RegisterStartupScript("focus", s)
>> End Sub
>>
>> Calling SetFocus( )
>> Me.SetFocus(Me.TextBox1)
>>
>> From...
>> http://www.objectsharp.com/Tips/archive/tip_2002_02_27.asp
>>
>>
>>
>>
>> -----Original Message-----
>> From: David Adames [mailto:david@p...]
>> Sent: Thursday, July 25, 2002 8:03 PM
>> To: ASP+
>> Subject: [aspx] RE: <input> box focus
>>
>>
>> I realize now that I have been seeing the focus method for Winforms not
>> for
>> Webforms. More research...
>>
>> -----Original Message-----
>> From: J Donahue [mailto:jdonahue@f...]
>> Sent: Thursday, July 25, 2002 8:24 PM
>> To: ASP+
>> Subject: [aspx] <input> box focus
>>
>>
>> I know Javascript uses focus to target an <input> box. Is there a way
to
>> target a certain <input> box from within a NET server control??
>> I have a form and have disabled the enterkey, replacing it with the tab
>> key. The zip code field checks the user entry and if found, fills in
the
>> city, state. The problem is, once it does that the cursor is no longer
>> on the form. I simply want to target the next <input> box
>> thanks!!
>>
>>
>>
>
>
_> ________________________________________________________________
J> oin the world?s largest e-mail service with MSN Hotmail.
h> ttp://www.hotmail.com
|
|
 |