views:

1290

answers:

2

I have an asp web page(login.aspx) that uses a master page (master.page).

I need to set focus to an asp:textbox(TextBox1) that is inside an asp:Panel(Panel1) on Login.aspx

I want to set focus to TextBox1 on an asp:Button click event (or page load on login.aspx for testing, I've tried both).

I have tried the following solutions with no success:

  • Page.SetFocus(TextBox1.ClientID);
  • Page.SetFocus(TextBox1);
  • Page.SetFocus(TextBox1.ClientID)
  • TextBox1.Focus();
  • TextBox Test = (TextBox)Panel1.FindControl("TextBox1");
  • Test.Focus();
A: 

Ok I found the answer, the code works fine in IE8 But not firefox for some reason

Anyone know why SetFocus() or Focus() doesn't work in firefox, are there any solutions?

David
What was your final solution that worked in IE8?
zakster82
Any of the original solutions I explain above all working in IE8, none in firefox. It think it might be something my end. Thanks
David
+2  A: 

When using ASP.NET AJAX I use the ScriptManager to set focus...

ScriptManager.GetCurrent(this.Page).SetFocus(this.FirstNameTextBox);
zakster82