Error "Operation is not valid due to the current state of the object"
-
Friday, January 20, 2006 2:23 PM
I'm trying to use the ReportViewer control (in remote mode) in a winform app. Everything works great until I try and change the ReportPath of the control (in response to a TreevIew after select event ) when the currently visible report is a report that has been drilled into from the original report specified in ReportPath e.g.
ReportViewer rv = new ReportViewer();
/* other code */
rv.ServerReport.ReportPath = "/Report1";
rv.RefreshReport();User then clicks on a link in Report 1 that jumps to Report 2 (still within the same control).
Now if you try and set the ReportPath to anything you get an "Operation is not valid due to the current state of the object" being thrown by the internal set_ReportPath method. As long as the ReportViewer control is showing Report1 all is well (for example if the user drilled down and them navigated back to the top level report). Is there something I should be doing differently? The only way round this at the moment is to create a new ReportViewer control everytime a different node is selected in the treeview which seems wrong as all I want to do is change the report path and parameters for the existing control.
Answers
-
Friday, January 20, 2006 4:15 PMModerator
While you are in a drillthrough report, the LocalReport object represents the drillthrough report - the value of the report path, parameters, etc. Conceptually, you can't change this report, it was defined by the parent report. If you could, it would leave the back button enabled on the toolbar, which doesn't really make sense. The correct thing to do is first call ReportViewer.Reset(). This will reset the report stacks and allow you to set a new definition.
All Replies
-
Friday, January 20, 2006 4:15 PMModerator
While you are in a drillthrough report, the LocalReport object represents the drillthrough report - the value of the report path, parameters, etc. Conceptually, you can't change this report, it was defined by the parent report. If you could, it would leave the back button enabled on the toolbar, which doesn't really make sense. The correct thing to do is first call ReportViewer.Reset(). This will reset the report stacks and allow you to set a new definition. -
Friday, January 20, 2006 11:14 PM
Thanks Brian, that worked perfectly
-
Saturday, January 21, 2006 11:15 PM
For the webform control there doesn't seem to be a Reset method but what I have done is just called the PerformBack method recursively to get back to the top level before modifying the report path. Is that the correct approach ? e.g.
private void GetBack()
{
if (rv.ServerReport.IsDrillthroughReport)
{
rv.PerformBack();
GetBack();
}
}private void ShowReport(String instance)
{
GetBack();
rv.ServerReport.ReportPath = RPT_INSTANCE_SUMMARY;
ReportParameter rp = new ReportParameter("instance", instance, false);
rv.ServerReport.SetParameters(new ReportParameter[] { rp });
} -
Tuesday, January 24, 2006 3:02 AMModerator
That approach will work. You could also swap out instances of the report viewer on the form, though it will require you to set property values on the viewer control again:
ControlCollection coll = oldViewer.Parent.Controls;
int oldIndex = coll.IndexOf(oldViewer);
ReportViewer newViewer = new ReportViewer();
coll.AddAt(oldIndex, newViewer);
coll.Remove(oldViewer); -
Tuesday, January 24, 2006 2:58 PMThanks Brian, just wanted to make sure I wasn't missing something (again)
-
Monday, March 13, 2006 10:51 AMI'm sorry, but why in the world is there no .Reset() method on the WebForms viewer? Having to do this is ridiculous, especially given the fact that this method exists on the WinForms viewer.
-
Wednesday, May 17, 2006 6:24 PMI'm having the same problem as well. The GetBack() method is working about 95% of the time, however i still will get an error occasionally, it would be nice if there was a reset() method to call and solve all my problems.
-
Thursday, May 18, 2006 1:46 AMModeratorWe are aware of this limitation and the problems it is causing people. We hope to address this soon in an update.
-
Tuesday, August 22, 2006 12:47 AM
We were using the following code to get back to the parent report in the web application.
But if we keep the session idle for more than 6 min(if we do with in that time period it works perfectly), SSRSReportViewer.PerformBack(); will throw an error
"This operation can only be performed on drillthrough report".
protected void btnBack_Click(object sender, EventArgs e)
{
GetParentReport();
SSRSReportViewer.ServerReport.ReportPath = "/" + ReportFolder + "/" + this.ReportName.ToString();
SSRSReportViewer.ServerReport.Refresh();
}
private void GetParentReport()
{
if (SSRSReportViewer.ServerReport.IsDrillthroughReport)
{
SSRSReportViewer.PerformBack();
GetParentReport();
}
}
-
Wednesday, September 13, 2006 3:31 PM
Any update on when this method will be added to the web version of the Report Control?
The hack works OK, but as Thambu states, the PerformBack method will throw an exception ("This operation can only be performed on a drillthrough report" - even when it is a drillthrow report and the IsDrillthroughReport property is true), if the page is idle for a couple of minutes...
-
Thursday, September 28, 2006 2:40 AMModeratorThe method is added in Visual Studio 2005 SP1.
-
Thursday, October 05, 2006 1:56 PMWhen will SP1 be released?
-
Monday, October 16, 2006 8:38 PM
Here is the hacky way I worked around this shortcoming. If setting the report path fails I call PerformBack() and then try setting the report path again. If I'm 5 levels deep this still works. I will rip this code out as soon as .Reset() is availiable.
bool l_bRetry = true;while (l_bRetry)
{
try
{
m_viewer.ServerReport.ReportPath = m_reports.SelectedItem.Value;
l_bRetry = false;
}
catch
{
m_viewer.PerformBack();
}
} -
Monday, October 23, 2006 12:43 AMModerator
A more elegant way to do that is:
while (m_reportViewer.ServerReport.IsDrillthroughReport)
m_reportViewer.PerformBack(); -
Monday, October 23, 2006 12:45 AMModeratorThe latest information on SP1 is available at: http://msdn.microsoft.com/vstudio/support/servicing/
-
Wednesday, January 03, 2007 8:19 PM
Hi Brian,
I'm able to view sample AdventureWork reports in Report Designer Preview mode but not over the browser when I deploy the same. The error that I get is:
Operation is not valid due to the current state of the object.Appreciate any help on this.
Thanks.
-
Tuesday, March 06, 2007 9:30 AM
Hi,
I am praveen. I am new to .net.I am designing a website which needs to displays reports . I used Report Viewer which is in Update Panel control to display Reports.We have many some Reports with child reports.
The navigation from Parent Report to Child Report and vice-versa is working fine only through the BACK button provided by report viewer.As this button navigates us to only the previous page but not the previous report its a flaw to our functionality.
In the child report we added a functionality, by adding a 'Back ' link button, to return to parent report as per the requirement .
On navigating through this 'Back' link button I am getting this error "Operation is not valid due to the current state of the object." while re-running the same report again or running other reports i am facing this problem .Can any one help me out in this problem.
-
Monday, October 15, 2007 10:41 PM
Works like a champ, Thanks Brian.
Bhushan

