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?
:)
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?
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?
Re: How do I call Vbscript functions from VB.net code behind files?
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.
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 :)
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?
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() ?
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.
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:
Dim strSCript As String = "<script language=VBScript>Call StartScan()</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strSCript)
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?
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?
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.
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
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.
:eek2:
Re: How do I call Vbscript functions from VB.net code behind files?
Try it with a very simple VBScript call?
Re: How do I call Vbscript functions from VB.net code behind files?
Moved to ASP.NET Forum. ;)
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 ?
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?
Re: How do I call Vbscript functions from VB.net code behind files?
Hi,
Ok, heres the code in VB.
VB Code:
Private Sub dgSteps_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgSteps.SelectedIndexChanged
Dim strSCript As String = "<script language=VBScript>Call change()</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strSCript)
End If
The code in ASPX page is:
VB Code:
<script language="VBScript" defer>
Sub change()
document.Form1.textbox1.value = "Trytochange"
End Sub
</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 ?
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????