Set Focus
-
Hi, I have a Textbox on my form(Web Control). On the page load I want to setfocus to this textbox. I have tried out following lines of code in body onload one by one, but its not working. 1) document.all['TXTDESC'].focus() 2) window.document.all['TXTDESC'].focus() 3) document.form1.TXTDESC.focus() Chintan
-
Hi, I have a Textbox on my form(Web Control). On the page load I want to setfocus to this textbox. I have tried out following lines of code in body onload one by one, but its not working. 1) document.all['TXTDESC'].focus() 2) window.document.all['TXTDESC'].focus() 3) document.form1.TXTDESC.focus() Chintan
Well depends upon the context. JavaScripting? document.Form1.TXTDESC.focus() has to work. Note the F is capital. JavaScript is case sensative. If you are working on ASP .NET, then Form1 is most likely to be the name of the only form. mE! ------------------- Therez No Place like ... 127.0.0.1
-
Well depends upon the context. JavaScripting? document.Form1.TXTDESC.focus() has to work. Note the F is capital. JavaScript is case sensative. If you are working on ASP .NET, then Form1 is most likely to be the name of the only form. mE! ------------------- Therez No Place like ... 127.0.0.1
Hi, Thanx for the replay. But I am getting this error while runing the code. Error Message: BC30456: 'document' is not a member of 'ASP.community_aspx'. Source Error: Line 21: Line 22: Chintan
-
Hi, Thanx for the replay. But I am getting this error while runing the code. Error Message: BC30456: 'document' is not a member of 'ASP.community_aspx'. Source Error: Line 21: Line 22: Chintan
Here use this. This does the trick for me. I put the function in my middle tier so all the pages can use it. Hence, that is why I am passing the page object.
'In a module or in an inherited class put the following constants.
Public Const C_ES As String = ""
Public Const JS_ScriptBegin As String = ""
Public Const JS_ScriptEnd As String = ""
Public Const JS_CtrlSetFocusBegin As String = JS_ScriptBegin _
& "document.getElementById('"
Public Const JS_CtrlSetFocusEnd As String = "').focus();" _
& JS_ScriptEndPublic Const JS_CtrlSelectBegin As String = JS_ScriptBegin _
& "document.getElementById('"
Public Const JS_CtrlSelectEnd As String = "').select();" _
& JS_ScriptEnd'In the Business Object Tier or in the page itself put the following sub
Friend Sub SetFocus(ByVal Ctrl As Control, ByVal WebPage As Page)
Try
If Not Ctrl Is Nothing Then
Dim ctrlID As String = Ctrl.ID
If Not ctrlID.Equals(C_ES) Then
WebPage.RegisterStartupScript("Focus", JS_CtrlSetFocusBegin & ctrlID & JS_CtrlSetFocusEnd)
'If the control is a TextBox select all of the text.
If TypeOf Ctrl Is TextBox Then
WebPage.RegisterStartupScript("Select", JS_CtrlSelectBegin & ctrlID & JS_CtrlSelectEnd)
End If
End If
End IfCatch ex As Exception Throw ex End Try End Sub 'set focus 'To call the sub with it being in the Busines Ojbect, BO, use the following BO.SetFocus(ddlOffice, Me) 'To call the sub while it is residing in the page class use the following SetFocus(ddlOffice, Me)
Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)