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_ScriptEnd
Public 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 If
Catch 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)