Set focus to Textbox when page starts?

jsandoval

Active member
Joined
Dec 27, 2004
Messages
28
Location
Denver
Programming Experience
10+
Hello all,

I am very new to web development and Visual Studio so I have not discoverd how to perform a lot of web app features as of yet. My question is how do I set focus to the first input textbox of a web page when it first displays?:confused:

Thank you in advance for any input.
 
In html code view you can use Javascript to set focus, for example in body onload event:
HTML:
<body onload="document.getElementById('txtSample').focus()">
 
Thank you for your response John.

I tried your code but did not get the desired result. Perhaps I have posed the question incorrectly, what I mean by focus is I want the cursor to be positioned in the first text box (ie. txtUserID) when the page first displays, so the user does not have to tab to or click on the text box before they start typing.

Thanks again.
 
Thank you again John.

The code snippet in beansoftware did the trick:

Page.RegisterStartupScript("SetFocus", _
"<script>document.getElementById('" & txtUserID.ClientID & _
"').focus();</script>")

Thanks once again for you help.
 
Back
Top