Set Focus
ASP.NET
3
Posts
2
Posters
0
Views
1
Watching
-
-
There are lots of different ways to do it, but here is a function that you can use for setting the focus on loading of page.
'"name" is the control's ID Private Sub FocusOnControl(ByVal name As String) Dim strBuilder As String = "" strBuilder += "<script language='javascript'>" strBuilder += "document.getElementById('" + name + "').focus();" strBuilder += "</script>" RegisterStartupScript("FocusOnControl", strBuilder) End Sub
Then in say in your Page_Load you can call the function
Private Sub Page\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load FocusOnControl("txtBox") End Sub
-
There are lots of different ways to do it, but here is a function that you can use for setting the focus on loading of page.
'"name" is the control's ID Private Sub FocusOnControl(ByVal name As String) Dim strBuilder As String = "" strBuilder += "<script language='javascript'>" strBuilder += "document.getElementById('" + name + "').focus();" strBuilder += "</script>" RegisterStartupScript("FocusOnControl", strBuilder) End Sub
Then in say in your Page_Load you can call the function
Private Sub Page\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load FocusOnControl("txtBox") End Sub