Set reportviewer properties through javascript


B

Bruce Parker

I have embedded a ReportViewer control in an aspx page. I want to be able to
set the ReportPath in the ServerReport tag from javascript and then get the
report to refresh itself without the whole page posting back.

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%"
Height="500px" Font-Names="Verdana" Font-Size="8pt"
ProcessingMode="Remote">
<ServerReport ReportPath="/Production/InternalMetrics/Active
Employee Report"
ReportServerUrl="http://itautomation/reportserver" />
....

<script type="text/javascript">
function MainBodyMethod(reportPath) {
/* set report path */
}
</script>

How do I do this?


</rsweb:ReportViewer>
 
Ad

Advertisements

H

Hongye Sun [MSFT]

Hi Bruce,

Welcome to Microsoft Newsgroup Service. My name is Hongye Sun [MSFT] and it
is my pleasure to work with you on this issue.

This is not an easy question, because ReportViewer control saves ReportPath
information in server's session, and only server code can change it. But if
we want to get the report to refresh itself without the whole page posting
back, there is no way for us to execute our server side code. In order to
well illustrate that, I will provide some backgrounds of ReportViewer
control so that you will be clear about what the problem we are facing.

1. How ReportViewer refreshes itself?
ReportViewer control supports Asynchronous Rendering
(http://msdn.microsoft.com/en-us/library/ms252090.aspx). What behind the
hood is that it uses an iframe to send request to its HttpHandler to
render. The request includes a session id which is used by the HttpHandler
to get the ServerReport information from session.

2. Why not use ReportViewer events with Asynchronous Rendering?
You may wonder why not we use ReportViewer events (such as ReportRefresh)
to execute our code to change the session. The reason is that ReportViewer
will automatically switch the render mode from asynchronous to full page
post back when it finds any events are registered. So during the
Asynchronous Rendering process, we have no way to execute our server code.

3. Why not use UpdatePanel?
The current version of ReportViewer control is not compatible with ASP.NET
Ajax Extension. The product team has already known this issue and plan to
fix it in future releases.

Now let us get back to this question. Based on current situation, we have
one possible workaround.

* Using IFRAME to host a ReportViewer control *

In this way, we have to put ReportViewer control into another web page like
"ReportPanel.aspx" and, in its original place, put an IFRAME which "src"
attribute points to the ReportViewer web page URL. For example,
the original page will looks like:
<iframe src="ReportPanel.aspx"></iframe>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="MainBodyMethod('/Production/InternalMetrics/Active Employee
Report'); return false;" />

<script type="text/javascript">
function MainBodyMethod(reportPath) {
var f = document.getElementById('ifrReport');
f.src = "ReportPanel.aspx?ReportPath=" + reportPath;
}

</script>
Here, we pass a parameter named "ReportPath" to ReportPanel.aspx page, and
in that page, we set it to ReportViewer control. The code will look like:

protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.Params["ReportPath"] != null)
{
this.ReportViewer1.ServerReport.ReportPath =
this.Request.Params["ReportPath"];
}
}

This way has one limitation that we cannot reference the report control in
its original page. The only way to communicate with the report control is
using URL parameters.

Please let me know if you have anything unclear. I will be more than happy
to be of assistance. Thanks.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Bruce Parker

Superb answer. Thanks very much!

"Hongye Sun [MSFT]" said:
Hi Bruce,

Welcome to Microsoft Newsgroup Service. My name is Hongye Sun [MSFT] and it
is my pleasure to work with you on this issue.

This is not an easy question, because ReportViewer control saves ReportPath
information in server's session, and only server code can change it. But if
we want to get the report to refresh itself without the whole page posting
back, there is no way for us to execute our server side code. In order to
well illustrate that, I will provide some backgrounds of ReportViewer
control so that you will be clear about what the problem we are facing.

1. How ReportViewer refreshes itself?
ReportViewer control supports Asynchronous Rendering
(http://msdn.microsoft.com/en-us/library/ms252090.aspx). What behind the
hood is that it uses an iframe to send request to its HttpHandler to
render. The request includes a session id which is used by the HttpHandler
to get the ServerReport information from session.

2. Why not use ReportViewer events with Asynchronous Rendering?
You may wonder why not we use ReportViewer events (such as ReportRefresh)
to execute our code to change the session. The reason is that ReportViewer
will automatically switch the render mode from asynchronous to full page
post back when it finds any events are registered. So during the
Asynchronous Rendering process, we have no way to execute our server code.

3. Why not use UpdatePanel?
The current version of ReportViewer control is not compatible with ASP.NET
Ajax Extension. The product team has already known this issue and plan to
fix it in future releases.

Now let us get back to this question. Based on current situation, we have
one possible workaround.

* Using IFRAME to host a ReportViewer control *

In this way, we have to put ReportViewer control into another web page like
"ReportPanel.aspx" and, in its original place, put an IFRAME which "src"
attribute points to the ReportViewer web page URL. For example,
the original page will looks like:
<iframe src="ReportPanel.aspx"></iframe>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="MainBodyMethod('/Production/InternalMetrics/Active Employee
Report'); return false;" />

<script type="text/javascript">
function MainBodyMethod(reportPath) {
var f = document.getElementById('ifrReport');
f.src = "ReportPanel.aspx?ReportPath=" + reportPath;
}

</script>
Here, we pass a parameter named "ReportPath" to ReportPanel.aspx page, and
in that page, we set it to ReportViewer control. The code will look like:

protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.Params["ReportPath"] != null)
{
this.ReportViewer1.ServerReport.ReportPath =
this.Request.Params["ReportPath"];
}
}

This way has one limitation that we cannot reference the report control in
its original page. The only way to communicate with the report control is
using URL parameters.

Please let me know if you have anything unclear. I will be more than happy
to be of assistance. Thanks.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ad

Advertisements

H

Hongye Sun [MSFT]

You are welcome, Bruce. It is also my pleasure to work with you.

Thanks for using Microsoft Newsgroup Service.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top