Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Active Control? 2

Status
Not open for further replies.

Junior1544

Technical User
Apr 20, 2001
1,267
US
Is there on the server side that I can say, Put the curson in a certain control because I would like to make the web page i'm building a little better...

Thanks...
--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
I'm not usre if this is what you mean but...
I use this to put the focus on the "LoginName" text box in a login page (when it loads).
<body onload=&quot;document.nameOfYourForm.nameOfYourTextBox.focus()&quot;>

I hope this helps.

jerasi
 
ok, that's exacly what I want... Where do I put it?

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Copy the &quot;<Body onload....>&quot; from above and paste it in your html page, dont forget to rename the code with your form name and text box name.

jerasi
 
Thank you much. There's a star.

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
If you have pages that you want different controls to be in focus depending on certain options, I have built this sub to set the focus in your code. Just call the sub from your page_load and pass it the control you want to have focus.

Public Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim sb As New StringBuilder()
sb.Append(&quot;<SCRIPT language='javascript'>document.getElementById('&quot;)
sb.Append(ctrl.ID)
sb.Append(&quot;').focus() </SCRIPT>&quot;)

RegisterStartupScript(&quot;focus&quot;, sb.ToString)

sb = Nothing
End Sub


This procedure works within user controls.

Public Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim sb As New StringBuilder()
sb.Append(&quot;<SCRIPT language='javascript'>document.getElementById('&quot;)
sb.Append(Me.UniqueID)
sb.Append(&quot;:&quot;)
sb.Append(ctrl.ID)
sb.Append(&quot;').focus() </SCRIPT>&quot;)

Page.RegisterStartupScript(&quot;focus&quot;, sb.ToString)

sb = Nothing
End Sub
That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Thanks for the submission, especially the mod for use in a UserControl. I am finding in my app that the script contends with SmartNavigation for which control gets focus, and the script is losing! If I find a way around this (other than turning SmartNavigation off) I'll post it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top