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!

Setting focus to asp textbox on demand

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all

I have 2 asp textboxes on my page - one for username and one for password. I need to set focus to one them and select the text - depending on whether the user enters an incorrect username or password. I found the great code in the post by jfrost10 - but I need this to be a bit more dynamic - namely that I could specify a different control to set focus to - depending on the outcome of the error. Currently this only allows me to specify one control in the Page_Load method.

Any help please [wiggle]

Thanks as always

Craftor :cool:
 
Hey Craftor,

You can actually use that code outside of hte page load. I use it in exactly the way you're trying to:

I have a username and password textbox. When the user clicks "enter" it checks to see if the user is validated. If they aren't, i have some code to clear the boxes and then I say

SetFocus(txtUserName)

and when it posts back it sets the focus to the username textbox.

The trick is to make sure you use

If Not Page.IsPostBack Then

End If

in your page load event, so that it sets the original focus only on the initial load.

D'Arcy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top