View Full Version : Help in JavaScript with VB Dot Net Code

12-27-2012, 11:44 AM
I have a vb.net application and from that application, we are generating SQL Server 2008 R2 Reports (SSRS) and as per the client request, we need to restrict the print icon on the Toolbar of SQL Server Reporting Service ONLY for a report and it should be made available for others. The Report Viewer Control is different for different Report Viewers and in this case, I want to check the availability of a Print control and if it is available I have to disable that. The Code we are using is as follows:

Private Sub wbReport_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles wbReport.NavigateComplete2
Dim scriptDisablePrint As String

' For some Report Viewers, Print Button is :ReportViewerControl_ctl06_ctl06_ctl00_ctl00'

scriptDisablePrint = "setTimeout(""Sys.Application.add_init(function() {var menu = document.getElementById('ReportViewerControl_ctl06_ctl06_ctl00_ctl00'); menu.parentNode.parentNode.disabled=true;})"", 10);"

' For some Report Viewers, Print Button is :ReportViewerControl_ctl05_ctl06_ctl00_ctl00'

scriptDisablePrint = "setTimeout(""Sys.Application.add_init(function() {var menu = document.getElementById('ReportViewerControl_ctl05_ctl06_ctl00_ctl00'); menu.parentNode.parentNode.disabled=true;})"", 10);"

' By combining the above two controls, I modified the JS Code as follows:'

scriptDisablePrint = "setTimeout(""Sys.Application.add_init(function(){var menu = document.getElementById('ReportViewerControl_ctl05_ctl06_ctl00_ctl00');If (!menu) { menu = document.getElementById('ReportViewerControl_ctl06_ctl06_ctl00_ctl00');} menu.parentNode.disabled=true;})"", 10);"

' Below lines are for Execution'
Dim headPrint As IHTMLElement = (CType(doc.getElementsByTagName("head"), IHTMLElementCollection)).item(0)

Dim scriptPrint As HTMLScriptElementClass = CType(doc.createElement("script"), HTMLScriptElementClass)

scriptPrint.setAttribute("type", "text/javascript")
scriptPrint.text = scriptDisablePrint
End Sub

While using the JS code combining both the controls,I'm getting error like Expected ';' or Expected '('.
Please help me to overcome this as I am new to Java Scripts.

Thanks in advance....