Setting Initial Control Focus on a Web Form

MM .NET Web Forms have a FocusedControl property that allows you to specify which control receives focus when a form first loads. You can continue to use this property in MM .NET 2.0, but ASP.NET 2.0 has a new focus API you can use instead. You can call the Page.SetFocus() method passing the ID of the control you want to receive focus or you can call the Focus() method on the control. You can also set the DefaultFocus property of the Form element to the ID of a control you want to receive focus when the page first loads

If you want to continue to use the MM .NET FocusedControl property you can set it in the form's load.

For example, in C#:

protected void Page_Load(object sender, EventArgs e)
{    
	this.FocusedControl = this.txtShipName;
}

And in VB .NET:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   Me.FocusedControl = Me.txtShipName
End Sub



© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 05/17/13
Comment or report problem with topic