Results 1 to 20 of 20

Thread: How do I call Vbscript functions from VB.net code behind files?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Arrow How do I call Vbscript functions from VB.net code behind files?

    Hi gang,

    I have a problem.

    I need to call some VBScript function from my code behind file. Tis is because, only under certain condition, would the Vbscript function be needed to be called.

    How do I go about doing it?


  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Re: How do I call Vbscript functions from VB.net code behind files?

    Why dont you just rewrite the script function into the code behind?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Quote Originally Posted by Cander
    Why dont you just rewrite the script function into the code behind?
    Because the script function must be at client side.
    meaning, it must be a client side coding. If i were to put it on server side, my authentication system will fail

    Do you have some suggestions?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    Is this an ASP.NET app?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    If it is, you can use Page.RegisterStartupScript() to execute your client side scripts on page load.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Quote Originally Posted by mendhak
    If it is, you can use Page.RegisterStartupScript() to execute your client side scripts on page load.
    Yes, it is ASP.NET Web app.
    Thanks, i'll try
    Last edited by aspfan; Jun 25th, 2005 at 05:40 AM.

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Hi,

    I manage to call my VBscript subroutine from my code behind file.
    But i encounter another problem. The button is in my datagrid.

    So, right now, im having problem doing it such that the attribute is not assigned to the button unless i click my button twice.
    (clicking the button will invoke datagrid On_SelectedIndexChanged event.

    It looks something like this. RolloverButton.Rollover is behaves just like a normal button.
    Code:
    Dim imgActivate As RolloverButton.RollOver = CType(dgSteps.SelectedItem.FindControl("imgActivate"), RolloverButton.RollOver)
            imgActivate.Attributes.Add("onClick", "vbscript:StartScan()")
    Looks like i have to put this set of coding somewhere..but where?

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Page.RegisterStartupScript() .
    I tried using it.
    Looks like i have to type the whole VBscript in code behind file. Cant i just called the VBScript from code behind using Page.RegisterStartupScript() ?

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    Yes. Place the function in the ASPX file, and in your Page.RegisterStartupScript, simply call the function/sub name.

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Quote Originally Posted by mendhak
    Yes. Place the function in the ASPX file, and in your Page.RegisterStartupScript, simply call the function/sub name.
    I did that.

    VB Code:
    1. Dim strSCript As String = "<script language=VBScript>Call StartScan()</script>"
    2.  
    3.         If (Not Page.IsStartupScriptRegistered("clientScript")) Then
    4.             Page.RegisterStartupScript("clientScript", strSCript)
    5.         End If

    Thats what i did. however, it return me a dialog box pop up saying "End of statement expected".

    I dont understand what it means. Something went wrong?

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    You get this error from the IDE or on the web page?

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    I got it on the web page. Meaning, when i preview the webpage on internet explorer, i got that error message.

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    I think that means you have a script error in what youv'e written. Try checking the Sub you've witten

  14. #14

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Quote Originally Posted by mendhak
    I think that means you have a script error in what youv'e written. Try checking the Sub you've witten
    That is weird.
    Because, I tried calling it using ASP.NET button by adding attribute to the button. When i click the button, it behaves as expected( i did not change alter any of my VBScript)

    Is it the limitation of RegisterStartupScript ?
    As in, it could not call VBScript functions.


  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    Try it with a very simple VBScript call?

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I call Vbscript functions from VB.net code behind files?

    Moved to ASP.NET Forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Quote Originally Posted by mendhak
    Try it with a very simple VBScript call?
    Hi, Yes, i have tried it. Something like, changing the values of HTML textbox.
    Still doesnt work.
    Something wrong with my VS.NET ?

  18. #18
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I call Vbscript functions from VB.net code behind files?

    Probably not. More likely with some code written. Would it be possible to post all of it?

  19. #19

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    45

    Re: How do I call Vbscript functions from VB.net code behind files?

    Hi,

    Ok, heres the code in VB.

    VB Code:
    1. Private Sub dgSteps_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgSteps.SelectedIndexChanged
    2.        
    3.         Dim strSCript As String = "<script language=VBScript>Call change()</script>"
    4.  
    5.  
    6.         If (Not Page.IsStartupScriptRegistered("clientScript")) Then
    7.             Page.RegisterStartupScript("clientScript", strSCript)
    8.         End If

    The code in ASPX page is:

    VB Code:
    1. <script language="VBScript" defer>
    2.  
    3. Sub change()
    4. document.Form1.textbox1.value = "Trytochange"
    5. End Sub
    6.  
    7. </script>


    As you can see, I want this VBscript sub to be called only when the datagrid is selected. Im using a button to select the row in the datagrid.

    What is wrong with my coding ?

  20. #20
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: How do I call Vbscript functions from VB.net code behind files?

    I'm having the same problem

    code

    aspx.cs
    Page.RegisterStartupScript("hey","<SCRIPT language=\"vbscript\"> \n call test() \n</SCRIPT>");


    aspx
    <SCRIPT language="vbscript">
    'call test()
    sub test
    document.write("it works!!!!!!!!!!!!")
    end sub
    </SCRIPT>

    this doesnt work, does anyone know why????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width