Error trying to set focus

P

paul

Hi, I'm trying to use Page_Load to set focus to a
textbox1 and I get the following error:

"Object Doesn't Support This Property or Method".

Here is my VB code behind:
Dim scriptString As New System.Text.StringBuilder()

scriptString.Append("<script Language='javascript'>")
scriptString.Append("document.getElementByID
('TextBox1').focus();")
scriptString.Append("</script>")

Me.RegisterStartupScript("setFocus",scriptString.ToString)

I tested a few things:
1. Rename 'TextBox1' to 'ABC' (garbage string) and I get
the same error. This tells me that I may actually have a
code behind syntax error, but it isn't reported as such.

2. I tried other variations where I used ampersand and Chr
(34) to encapsulate 'TextBox1', and it did not recognize
the ampersand (or the + sign) as characters that it could
use with a string. (?? This is very different than VB6
Windows apps.)

Any ideas what I might try besides running a script right
out of the ASP.NET? That does work, but I would like to
learn more about why this code behind is failing. Thanks,
Paul
 
R

Ravikanth[MVP]

Hi

In html body tag, you can call a javascript function and
set focus.

Ravikanth[MVP]
 
P

Paul LeBlanc

Hi, Ravikanth, that's exactly how I worked around the issue. I guess
you feel like setting it from the code behind isn't worth the trouble?
I sure would like to know why it doesn't work, but at least there is a
solid workaround. Thanks. Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top