Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error calling VBScript function in external module (ASP.NET)

Status
Not open for further replies.

MR1

Programmer
Feb 10, 2009
9
CA
Hello,

I have an ASP.NET page with an Input button that calls a function:
<input id="btnExport" type="button" value="Export Report" onclick="vbs: ExportReport()" />

And this is the function:
<script language="vbscript" type="text/vbscript">
Function ExportReport()
Msgbox “Ok”
End function
</Script>

Works fine if I place the function on the same page.

However, if I move the function in a module (MyModule1.vb) and I modify the code as follows:
<script language="vbscript" type="text/vbscript" src="MyModule1.vb">
(Note: I also tried to specify a path for MyModule1.vb…)

I am now getting this error: Microsoft VBScript runtime error: Type mismatch: 'ExportReport'

Any idea why is this happening?
Thank you,
M.R.
 
I think you're getting confused with server-side and client-side programming.

VBScript runs on the client (specifically in IE), whereas ASP.NET is a server-side language so putting any code in a .vb file will attempt to run it on the server (which is one of the reasons why it doesn't know what to do with the <script> tags).

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
Thank you for your reply Mark.
I am new to ASP.NET

I addded runat="server" as follows:
<input id="btnExport" type="button" value="Export Report"
runat="server" /></p>

and the function in vb module is:
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExport.ServerClick
msgbox "ok"
end sub

The only problem is that the whole page is refreshed when I click the button...
How can I prevent page refresh?

Thank you,
M.R.
 
Any server side button causes a post back and will refresh the page. The only way to avoid that is to use AJAX or an iCallBack interface. Also, msgbox or message box will only run on the server.
 
Thank you jbenson001, I added an AJAX UpdatePanel and this solved my problem!
 
The AJAX update panel will stop the flicker of the page, however, behind the scenes, the whole page still posts back. So, using many update panels on a page could slow the page down. Do some research to find out more.
 
Thank you jbenson001, i wasn't aware of this issue.
I may use client-side programming then.

Do you know by any chance where I can find vbscript (or javascript) code that exports a report to Excel?
I have a Microsoft reportviewer control on may page and a .rdlc report.
There is an Export button available on the reportviewer but it doesn't work correctly if there is a group on the report, that's why I am trying to implement an export function.

Thank you,
M.R.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top