Hi All,
My web application displays a report on one of its .aspx webpages coded in C#.
I am currently using a ReportViewer control to diplay the server report. I was trying to avoid the refresh of my report on every postback, by including it inside an AJAX Update Panel, it didn't work.
In my next trial, I tried to create a new report viewer control instance programatically and set its properties accordingly and then add this control to the Update panel'sContentTemplateContainer.Controls collection.
It looks like the control gets added to the Update Panel, however, It won't display on the page when it gets renedered. Below is a code snippet.
Please suggest. Thanks.
this.ReportViewer =newReportViewer();this.ReportViewer.ID ="rvID";
this.ReportViewer.ServerReport.ReportServerUrl =newUri("http://ReportServer");
ReportParameter[] parm =newReportParameter[6];parm[0] =newReportParameter("a","5");
parm[1] =newReportParameter("b","160");parm[2] =newReportParameter("c","NYP-BOS");
parm[3] =newReportParameter("d","Coach");parm[4] =newReportParameter("e","2007-01-01");
parm[5] =newReportParameter("f","2007-05-25");PanelReport.ContentTemplateContainer.Controls.Add(this.ReportViewer); (adding the Report Viewer to the Panel)
this.ReportViewer.ShowParameterPrompts =false;this.ReportViewer.ServerReport.SetParameters(parm);
this.ReportViewer.ServerReport.ReportPath ="/Reports/Report1";
Hi!
You should set theAsyncRendering="true"property of the ReportViewer (or setReportViewer.AsyncRendering =True in code-behind) to get async postbacks.
In that way, the report runs in an IFRAME which only refreshes when you re-render the report.
Let me know if it works for you or if you need the reports running in sync with the page. Some time ago I managed to use an UpdatePanel around them, but I ran into some issues that made me come back to the asyncrendering solution.
Hi, Thanks for the response, I have tried using that. It didn't work.
What I have is a Dropdown control, with Autopostback set to true; and an UpdatePanel somewhere else on the page. (the contenttemplate and triggers are empty on the .aspx page)
Programatically, inside the SelectIndexChange evenhandler for the dropdown, I am creating a ReportViewer control and set its properties as needed (also AsynRendering = true).
Now, I add this ReportViewer control to the control collection of the ContentTemplateContainer of the UpdatePanel.
I might be wrong in the sequence of the steps that I am doing...or something else, but whats happening is on the page I can see the report viewer template showing up which has 0 pages.
How and when does the report viewer control or the report gets rendered in the life cycle?
Thanks.
Hi!,
Yes, that may be the problem. The thing is that the SelectedIndexChanged gets fired even after the Page_Load, I'm not exactly sure "when" you have to generate the report, but could be too late. And a ReportViewer in asyncRender won't work inside an UpdatePanel, remeber that is actually an IFRAME.
But, if you are trying to fire an async postback for the SelectedIndexChanged event, the drop down list is the one that should be inside an UpdatePanel (you may already have that).
If that's you case, what you could do is add the ReportViewer outside the update panel and assign its properties in the markup code, and then call theReportViewer.ServerReport.Refresh() method on the SelectedIndexChanged event. If the ReportViewer is set to AsyncRender=true, you should have the same behavior as if it was inside an UpdatePanel.
Hope that helps,
Hi Juan, Based on your response I had partial success.
I made the following changes (Please note that my dropdown list is the first in a set of 3 cascading dropdown lists and all these are not inside any Update panel. They are working as expected whenever the selection changes on the first dropdown.
Took out the ReportViewer control from inside the Update panel and set the properties declaratively (AsyncRendering="true",ProcessingMode="remote",ShowParameterPrompts="false"and also added a <ServerReport> element with correct url and report path
Hi!, Well, I'm glad you are making some progress! :)
Mmmm...I'll start form your second question, and the answer is yes: You have to send the parameters set every time the report is generated.
Another option would be to use the embedded Report Parameters prompts, but it seems that you don't want to do that....
Remember that you can use ServerReport.GetParameters to get all you parameter info.
About the first one, what do you mean exactly when you say "the Report is not refreshing"?? Is trying to refresh, showing the "Generating Report" animated gif and then comes up blank?? It doesn't do anything at all? It comes up with an error??
Hey, that was quick! :)
Yes, I don't want the embedded parameter prompts.
Correct me if I am wrong, ServerReport.GetParameters gives me a readonly collection of parameter info objects right? what could I do with it?
Coming to the first question, By "not refreshing" what I meant was that the webpage sits with the report that it showed me on initial load, even on subsequent SelectIndexChange events (using debugger I can see the event being fired and the parameters being set and the call to report refresh). Its shows me the same report as If nothing happened, (the screen doesn't even flicker) I see the animated gif only on the initial page load.
I think..I would pick "doesn't do anything at all" from the choices that you have listed :)).
Thanks.
Hi!
Well, with the GetParameters you can get the Parameters Name, DataType, DefaultValue, etc,etc.
It's more useful if you want to dynamically create a toolbar or if you want to check that you are entering (SetParameters) all the required parameters with the right names, etc. You can build an array of Parameters and the use it's properties as reference in the SetParameters function.
About the report not refreshing, I would say that it's too late in the page life cycle to do that (as you can see, the SelectedIndexChanged event fires after Page_Load)
Having had a look at my solution, I saw that I'm refreshing the report on Page_Load avoiding to check for Page.IsPostBack.
Just to check, could you try NOT to refresh the report on SelectedIndexChanged and have a Button or something that refreshes the Report AFTER all the appropiate selections have been made in the DropDownLists? Just remember to move the code that sets the parameters and refreshes the reports to Page_Load.
Give it a try, if it works, you'll have the reason for your problem, altought maybe not the solution! :)
Cheers,
Based on the suggestion, I removed the code from the selectindexchange handler and placed something like the below in my page_load to test if the timinig in the lifecycle for the report refresh is the problem. I passed hard coded values to the parameters just so to make sure that the report output generated is different. The initial load was still good but not the postback, nothing happened on postback even from within the page_load. Sorry for all the trouble...I am desperately trying to get this working so as to complete an important assignment by this friday. Thanks.
page_load(object, EventArgs)
{
if (!IsPostback) /* Initial load*/
GenerateReport("a", "b", "c"); (some dummy values for this post)
else
GenerateReport("e", "f", "g"); // on postback
}
void GenerateReport( x,y,z)
{
reportparmeter [] parm = new reportparamete[3];
parm[0] = ..., parm [1] = ...; parm [2] = ...;
reportvwr.ServerReport.Setparameters(parm);
reprtvwr.ServerReprot.Refresh();
}
Mmmm..weird.......how are you generating the second post-back? Are you using a regular post back control like a Button outside an UpdatePanel?
I set the Autopostback on the first dropdownlist to true declaratively. I have a menu on my page too, so I can click on one of the menu items to generate a postback. In this case, should it matter how the postback is fired, because the page_load has hard coded calls for the report generation.
By the by, should the Asynrendering be set to true? (I have it set to true). I can't think of anything else..for now...ok time to go to work.
-Thanks
Hi Juan,
I noticed something, my report refreshes on only normal postbacks and not the asyncpostbacks. Is it okay to assume that, postbacks coming from any controls that are in some way related to an update panel (in or out of it) are always asyncpostbacks?
Thanks.
Hi!
Well, yes, that was the reason of my previous question: The reports will refresh only on a regular postback. If the control that fires the post back is not inside, but set as a trigger for some other update panel, it will fire an async postback.
If you put any control in a page, not inside and not associated with any UpdatePanel, a fire a postback from there, the reports work?
Cheers,
I have a hovermenu extender on my page not part of a update panel. The panel for the hover menu has a couple of link buttons. When I click those link buttons, a normal postback happens and my report gets refreshed.
This is so confusing, I am hoping that there is a thumb rule(s) of some kind for keeping things clear and simple with AJAX (or do's and don'ts). I am new to AJAX and I was wondering if you could recommend me a good design guide which says, how a particular functionality can be accomplished. Right now, I am just developing the code as I discover things, I am afraid if I end up making the code so inflexible for future changes.
Thanks.
What you are experiencing is exactly the same as I was:
The Reports could not be generated as a part of an async postback and in order to make them work properly they should be refreshed not later than in Page_Load...These could be two rules of thumb.
Keep in mind that the ReportViewer runs in a IFRAME while in asyncRendering=true, so it may be worthwhile investigating the interactions between these and AJAX...
No comments:
Post a Comment