Introduction
Managing client-side VBScripts is often necessary in some projects. Here is a solution how to do it. All VBScripts are held in a special project folder. The script is loaded into a hidden textbox and executed via JavaScript.

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim sText As String = "Hello!"
ClientBrowserVBScript("", "msgbox(" & Chr(34) & sText & Chr(34) & ")")
Dim sAdd1 As String = "sServerName=" & _
Chr(34) & Server.MachineName & Chr(34)
ClientBrowserVBScript("SayHello.vbs", sAdd1)
End Sub
Sub ClientBrowserVBScript(ByVal sVBScriptName As String,_
Optional ByVal sAddScript As String = "")
Dim sc As String = Replace(sVBScriptName, ".", "")
Dim sb As New System.Text.StringBuilder
sb.Append("<div style='position:" & _
"absolute;top:100;left:100;visibility:hidden;'>")
sb.Append("<textarea name='ClientBrowserVBScript" &_
sc & "' id='ClientBrowserVBScript" & _
sc & "' cols='100' rows='10'>" & vbCrLf)
sb.Append("On Error Resume Next" & vbCrLf)
sb.Append(sAddScript & vbCrLf)
If sVBScriptName <> "" Then
Dim fs As New StreamReader(Server.MapPath("ClientScripts/" _
& sVBScriptName))
sb.Append(fs.ReadToEnd)
fs.Close()
End If
sb.Append("</textarea></div>" & vbCrLf)
sb.Append("<script>" & vbCrLf)
sb.Append("onerror = stopError;" & vbCrLf)
sb.Append("function stopError()" & vbCrLf)
sb.Append("{" & vbCrLf)
sb.Append("return true;" & vbCrLf)
sb.Append("}" & vbCrLf)
sb.Append("sScript = window.document.getElementById(" _
& Chr(34) & "ClientBrowserVBScript" & _
sc & Chr(34) & ").value;" & vbCrLf)
sb.Append("javascript:window.execScript(sScript, " & _
Chr(34) & "VBScript" & Chr(34) & ");")
sb.Append("</script>")
Page.RegisterClientScriptBlock("ASPXClientBrowserVBScript" _
& sc, sb.ToString)
End Sub
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here