Sunday, August 31, 2008

Using SetFocus in an AJAX Panel

If you have a TextBox on a regular ASP.net web page then you can force the initial focus to it with code such as this:

SetFocus(textBox);

But if your web page is AJAX enabled then this won't work. But the following code will:

ScriptManager.GetCurrent(this).SetFocus(textBox);