Is it possible to embed Javascript inside an SSRS report?
Is it possible to embed Javascript inside an SSRS report?Mr Shaw
November 19th, 2010 5:12am

You should give more detail on what you are trying to do. You can use javascript in "navigational" options in certain report controls e.g. a script to open a new browser window when someone clicks a data row.
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 7:04am

Yes, Javascript can be embedded in an SSRS report. To embed it, please follow these steps - Take a textbox on your report. Set its text to the following - =Code.WriteHTML(" <script> Your Javascript code goes here </script> ") Set the Hidden property of this textbox to TRUE so that this code is not visible to the users. Write your javascript code within this textbox, as explained above. If you include Javascript in your report, please note that - If the report is exported to excel or pdf or any other format, it would be all messed up. Use javascript only if the reports would be viewed in the HTML format (internet explorer). Ensure that the Javascript is enabled in the browser. There can be a slight flicker when the report executes since the SSRS engine would render the report first and then the Javascript would run on this report to add new components/edit existing components. Please let me know in case you need any further information. Cheers, ShalinShalin Kapadia
November 19th, 2010 7:24am

Hi Shalin, Code.WriteHTML means that there should be some code with the function WriteHTML. Do you have that, would love to test this. Meanwhile, just check the link below for the same topic http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/fa6006fa-c50b-42f9-a162-367f47b03048Cheers, Jason P.S. : Please click the 'Mark as Answer' button if a post solves your problem! :)
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 9:06am

As Jason Thomas says bellow Code.WriteHTML indicates that there is a function called WriteHTML. Do you have the code for that function. ThanksMr Shaw
November 19th, 2010 9:32am

Sure. I'll create a sample project and share it with you guys shortly. Until then, ShalinShalin Kapadia
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 9:46am

No need for the whole project. We are just asking for the code for the VB function WriteHTML. This is a not a bult-in function as far as I know.Cheers, Jason P.S. : Please click the 'Mark as Answer' button if a post solves your problem! :)
November 19th, 2010 10:34am

Yes, WriteHTML is not a built-in function. Apologies for not including the code for this function in my previous post. This function should be created in the custom code section of the report. The code for this function is as follows - Function WriteHTML (ByVal Msg AS String) AS String System.Web.HttpContext.Current.Response.Write(Msg) Return "" End Function The assembly System.Web has to be referenced in your project in order to run the above mentioned code. The JavaScript code written in the textbox would be passed as a parameter to the WriteHTML function which would Let me know in case you need any further informaton. Cheers, ShalinShalin Kapadia
Free Windows Admin Tool Kit Click here and download it now
November 20th, 2010 12:20am

I have used System.Web.HttpContext.Current.Response.Write and I am now getting a message say: HttpContext is not a member of Web. I have added the system.web reference so I am not sure why i am getting this error?Mr Shaw
November 21st, 2010 10:20am

I have used System.Web.HttpContext.Current.Response.Write and I am now getting a message say: HttpContext is not a member of Web. I have added the system.web reference so I am not sure why i am getting this error?Mr Shaw
Free Windows Admin Tool Kit Click here and download it now
November 21st, 2010 10:20am

I red on http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-reporting/5391/Disable-Hyperlink-in-EXCEL "HttpContext.Current is not available when the report is previewed under the Report Designer so you have to check if it is null". Does this mean that your code will only work when I deploy to the report to the server? Mr Shaw
November 21st, 2010 12:27pm

Yes, thats correct. You wouldn't be able to test it from the BIDS. You will have to deploy the reports and test them from the reports manager.Shalin Kapadia
Free Windows Admin Tool Kit Click here and download it now
November 21st, 2010 12:32pm

Yes, thats correct. You wouldn't be able to test it from the BIDS. You will have to deploy the reports and test them from the reports manager.Shalin Kapadia
November 21st, 2010 12:32pm

Thanks for the help I give it a go.... I have been going round in circles with problem for days... I think i'll need therapy when it is finished. i'll post my results... :)Mr Shaw
Free Windows Admin Tool Kit Click here and download it now
November 21st, 2010 1:20pm

I deployed the report and used in the text box the following expression =Code.WriteHTML("<script>window.location = 'http://www.google.com'</script>") When I ran the report the text box show #Error. In BIDS, the error read Object reference not set to an instance of an object. I am not sure how to fix this problem. thanks for your help.Mr Shaw
November 21st, 2010 5:05pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics