Click here to Skip to main content
Licence 
First Posted 10 Mar 2004
Views 27,997
Bookmarked 12 times

Managing Client-side Scripts in the IDE

By | 10 Mar 2004 | Article
Manage Client-side ccripts in the IDE.

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.

Sample screenshot

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) & ")")

  'Pass addidional Variables
  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
  
  'Create a hidden Textarea as Script-Container
  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)
  
  'Append the VBScript from the Project
  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)
  'Suppress Javascript-Error
  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)

  'Extract the Script
  sb.Append("sScript = window.document.getElementById(" _
      & Chr(34) & "ClientBrowserVBScript" & _
      sc & Chr(34) & ").value;" & vbCrLf)

  'Execute VBScript under Javascript 
  sb.Append("javascript:window.execScript(sScript, " & _
              Chr(34) & "VBScript" & Chr(34) & ");")
  sb.Append("</script>")
  Page.RegisterClientScriptBlock("ASPXClientBrowserVBScript" _
                                                  & sc, sb.ToString)
End Sub

License

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

About the Author

dfrede



Germany Germany

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralASP.Net 2.0 feature: WebResource.axd PinmemberEric Newton10:10 6 Nov '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 11 Mar 2004
Article Copyright 2004 by dfrede
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid