Monday, December 18, 2006

put the focus on a ChangePassword Control UserName field

I was trying all sorts of things to set the focus to the UserName control of the ChangePassword Control, turns out it was as simple as:

if (!Page.IsPostBack)
ChangePasswordControl.Focus();

works for the Login Control too

if (!Page.IsPostBack)
LoginControl.Focus();

2 comments:

Anonymous said...

How odd, you are totally right. I'm wondering why I'm always using code like this?

TextBox userName = Login1.FindControl("UserName") as TextBox;

if (userName != null) Page.SetFocus(userName);

BlackTigerX said...

that's exactly what I was trying to do =oS, shame on us