Sure - you can inject some javascript into the page that does this for you:
Page.RegisterSt artupScript("Fo cusedControl",
"<script language='javas cript'>\r\ndocu ment.getElement ById('" +
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("Behav ior"),
Description("Se t the focus of this form when it starts to the specified
control ID")]
public Control FocusedControl
{
get { return this.oFocusedCo ntrol; }
set { this.oFocusedCo ntrol = value; }
}
Control oFocusedControl = null;
/// <summary>
/// Overriden to handle the FocusedControl property.
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(Eve ntArgs e)
{
if (this.FocusedCo ntrol != null)
this.RegisterSt artupScript("Fo cusedControl"," <script
language='javas cript'>\r\ndocu ment.getElement ById('" +
this.FocusedCon trol.ID + "').focus();\r\ n</script>\r\n");
base.OnPreRende r (e);
}
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/ http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"A.M" <no*****@online .nospam> wrote in message
news:un******** *****@TK2MSFTNG P10.phx.gbl...
Hi,
Can I configure a TextBox to have focus and cursor on it when page gets
loaded?
Thanks,
Alan