RegisterStartupScript - SetFocus


G

Guest

I'm trying to set focus to a control when the page is loaded. The control may be different from one entry to the next so I cannot just hardcode it into the <body onload..>. I've tried several variations using registerstartupscript, and I see the script before the <\form>, but it doesn't seem to fire. Here's my current code which is called in the page_load
Private Sub SetFocus(ByVal ttctrl As System.Web.UI.Control
Dim s As String
s = "<SCRIPT language=""javascript"">document.forms[0].item('" & ttctrl.ID & "').focus(); <SCRIPT>
RegisterStartupScript("setFocus", s
End Su
this is what appears in my html
<SCRIPT language="javascript">document.forms[0].item('txtStmtMnth').focus(); <SCRIPT

What am I doing wrong
Thank
 
Ad

Advertisements

G

Guest

Try.

s = "<SCRIPT language=""javascript"">document.forms[0].item('" & ttctrl.ID & "').focus(); <SCRIPT>

should b

s = "<SCRIPT language=""javascript"">document.forms[0].item('" & ttctrl.ID & "').focus(); </SCRIPT>

I think you forgot to close the script tag properly

Suresh

----- Lisa wrote: ----

I'm trying to set focus to a control when the page is loaded. The control may be different from one entry to the next so I cannot just hardcode it into the <body onload..>. I've tried several variations using registerstartupscript, and I see the script before the <\form>, but it doesn't seem to fire. Here's my current code which is called in the page_load
Private Sub SetFocus(ByVal ttctrl As System.Web.UI.Control
Dim s As String
s = "<SCRIPT language=""javascript"">document.forms[0].item('" & ttctrl.ID & "').focus(); <SCRIPT>
RegisterStartupScript("setFocus", s
End Su
this is what appears in my html
<SCRIPT language="javascript">document.forms[0].item('txtStmtMnth').focus(); <SCRIPT

What am I doing wrong
Thank
 
H

Harry Simpson

Lisa,

Check out:
http://www.devx.com/dotnet/articles/rj121801/rj121801-1.asp

I built a setfocus control using this article and just add it to the
toolbox, drag it onto an aspx page and set the one property. Then in code
behind you can reference the control in code changing focus whenever you
want. Works great!

HTH

Harry

Lisa said:
I'm trying to set focus to a control when the page is loaded. The control
may be different from one entry to the next so I cannot just hardcode it
into the <body onload..>. I've tried several variations using
registerstartupscript, and I see the script before the <\form>, but it
doesn't seem to fire. Here's my current code which is called in the
page_load:
Private Sub SetFocus(ByVal ttctrl As System.Web.UI.Control)
Dim s As String
s = "<SCRIPT language=""javascript"">document.forms[0].item('" &
ttctrl.ID & "').focus(); said:
RegisterStartupScript("setFocus", s)
End Sub
this is what appears in my html:
<SCRIPT
language="javascript">document.forms[0].item('txtStmtMnth').focus();
 
Ad

Advertisements


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

Top