DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Mike has posted 9 posts at DZone. View Full User Profile

Setting Focus To A Field In Asp.net

06.05.2008
| 4983 views |
  • submit to reddit
        This code does a simple field focus in asp.net.

    Protected Sub setFieldFocus(ByVal ctrl As System.Web.UI.Control)
        Dim s As String = "<SCRIPT language='javascript'>document.getElementById('" + ctrl.ClientID + "').focus() </SCRIPT>"
        ClientScript.RegisterStartupScript(Me.GetType, "focus", s)
    End Sub

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindData()
        End If
        setFieldFocus(txtSpecies)
    End Sub