Sure - you can inject some javascript into the page that does this for you:
Page.RegisterStartupScript("FocusedControl",
"<script language='javascript'>\r\ndocument.getElementById('" +
YourControl.Id + "').focus();\r\n</script>\r\n");
Better yet create a custom page class (or add it to your customized Page
class) by adding a FocusedControl property and then handling the insertion
automatically via the OnPreRender() event handler:
/// <summary>
/// Assigns focus to the specified control. Note the name must match the
exact
/// ID or container Id of the control in question.
/// Logic for this behavior is provided in OnPreRender()
/// </summary>
[Category("Behavior"),
Description("Set the focus of this form when it starts to the specified
control ID")]
public Control FocusedControl
{
get { return this.oFocusedControl; }
set { this.oFocusedControl = value; }
}
Control oFocusedControl = null;
/// <summary>
/// Overriden to handle the FocusedControl property.
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
if (this.FocusedControl != null)
this.RegisterStartupScript("FocusedControl","<script
language='javascript'>\r\ndocument.getElementById('" +
this.FocusedControl.ID + "').focus();\r\n</script>\r\n");
base.OnPreRender (e);
}
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/