focusing textbox at runtime
-
how can i focus a textbox at runtime in asp.net without using javascript
-
how can i focus a textbox at runtime in asp.net without using javascript
What is the reason why you don't want to use javascript? For me it worked great. The code is written in VB.Net.
Private Sub FocusOnControl(ByVal Name As String)
Dim strBuilder As String = ""
strBuilder += ""
strBuilder += "document.getElementById('" + Name + "').focus();"
strBuilder += ""
RegisterStartupScript("FocusOnControl", strBuilder)
End SubThen in the page load event call the FocusOnControl function:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
FocusOnControl("name of textbox")
End If
End SubYou can use the FocusOnControl("name of textbox") anywhere in your code and use any textbox you wish. I jump from textbox to textbox.\ Hope this helps.;)
-
What is the reason why you don't want to use javascript? For me it worked great. The code is written in VB.Net.
Private Sub FocusOnControl(ByVal Name As String)
Dim strBuilder As String = ""
strBuilder += ""
strBuilder += "document.getElementById('" + Name + "').focus();"
strBuilder += ""
RegisterStartupScript("FocusOnControl", strBuilder)
End SubThen in the page load event call the FocusOnControl function:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
FocusOnControl("name of textbox")
End If
End SubYou can use the FocusOnControl("name of textbox") anywhere in your code and use any textbox you wish. I jump from textbox to textbox.\ Hope this helps.;)