#Region "Automation Scripts"
''' -----------------------------------------------------------------------------
''' <summary>
''' SetFocus(). Sets Focus on a control on the page. Similar to something seen on a Windows Form.
''' </summary>
''' <param name="webControl">WebControl to focus on.</param>
''' <param name="htmlControl">HTML Control to focus on.</param>
''' <remarks>
''' </remarks>
''' <history>
''' [robz] 8/31/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Private Sub SetFocus(Optional ByVal webControl As System.Web.UI.Control = Nothing, Optional ByVal htmlControl As System.Web.UI.HtmlControls.HtmlControl = Nothing)
Dim setCursor As New System.Text.StringBuilder
Dim removeScript As Boolean = False
Dim controlname As String
'check to see if both are sent
If Not (webControl Is Nothing) And Not (htmlControl Is Nothing) Then
Dim ex As New Exception("You may only send one control, web or html. Not both.")
Throw ex
ElseIf Not (webControl Is Nothing) Then 'if it is a webcontrol
controlname = webControl.ClientID.ToString
ElseIf Not (htmlControl Is Nothing) Then 'if it is a htmlcontrol
controlname = htmlControl.ClientID.ToString
Else 'nothing has been passed and the script should be removed.
removeScript = True
End If
'check to see if the script should be removed.
If Not (removeScript = True) Then
'create the javascript
setCursor.Append("<script language='javascript'>")
setCursor.Append(vbCrLf & "function setCursor() {")
setCursor.Append(vbCrLf & " if (document.getElementById('" & controlname & "') != null) {")
setCursor.Append(vbCrLf & " document.getElementById('" & controlname & "').focus();")
setCursor.Append(vbCrLf & " }")
setCursor.Append(vbCrLf & "}")
setCursor.Append(vbCrLf & " setCursor();")
setCursor.Append(vbCrLf & "</script>")
'register the script
RegisterStartupScript("setCursor", setCursor.ToString())
Else
'register over the top of the script with nothing
RegisterStartupScript("setCursor", "")
End If
End Sub
#End Region