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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox focus 1

Status
Not open for further replies.

jkl

Programmer
May 16, 2001
83
US
Is there a way to set the "focus" to a dynamically generated text box?

here's the deal. i have a datagrid object, in which i have an &quot;edit&quot; link for each item. when the user clicks &quot;edit&quot;, the <edititemtemplate> is then used. however, the page is too long, and so when they hit &quot;edit&quot;, the page re-posts and is focused at the top of the page. i want it to focus on the record that's being edited. any ideas?
 
I wrote a FAQ about one method of doing this back in the ASP forum. It doesn't set the focus, but rather uses the document.body.scrollTop property in javascript to set the screen position on reload of a page. Same method still works with ASP.NET:

faq333-1037

:)
paul
penny1.gif
penny1.gif
 
I found an object that allows you to set the focus of controls by adding javascript to the page at run time. So far I haven't found any built in functionality in .Net for this which is odd.

Just give me a bit and I'll dig up that focus control for you. That'l do donkey, that'l do
[bravo]
 
Here's what we did to set the control to have focus. Its a sub that takes a control, and writes some script. Its all from teh codebehind though.

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)
Dim s As String =
&quot;<SCRIPT language='javascript'>document.getElementById('&quot;
& ctrl.ID & &quot;').focus() </SCRIPT>&quot;

RegisterStartupScript(&quot;focus&quot;, s)

End Sub

Jack
 
thanks Jack, that did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top