0

I've been tasked to display a rdl report which I managed to get working thanks to Microsoft's Report Viewer, however when changing the parameters and trying to refresh the report I get a Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request. Error.

Here is the report viewer in my aspx file,

<asp:ScriptManager ID="ScriptManager" runat="server"/>
                <asp:UpdatePanel ID="UpdatePanel" runat="server">
                    <ContentTemplate>
                        <rsweb:ReportViewer ID="ReportViewer" runat="server" ProcessingMode="Remote" Height="600px" Width="100%" ShowParameterPrompts="false" ShowToolBar="true"/>
                    </ContentTemplate>
                </asp:UpdatePanel>

This is my button I use to generate the report

<dx:ASPxButton ID="btnBuildReport" CssClass="btn btn-primary btnBuildReport" runat="server" Text="Build Report" AutoPostBack="False" OnClick="OnBuildReportClick"/>

This is my method for initializing the report - This method is called on page load.

Private Sub InitilizeReport()
        ReportViewer.ProcessingMode = ProcessingMode.Remote
        Dim serverReport As ServerReport = ReportViewer.ServerReport
        serverReport.ReportServerUrl = New Uri(SERVERURL)
        serverReport.ReportPath = REPORTPATH
        serverReport.ReportServerCredentials = New ReportViewerCredentials(USERNAME, PASSWORD)
    End Sub

This is the method that fires when the button is clicked, it adds the parameters and refreshes the report.

 Protected Sub OnBuildReportClick(sender As Object, e As EventArgs)
        Dim reportParameters As New ReportParameterCollection
        reportParameters.Add(New ReportParameter("Param1", PARAM1))
        reportParameters.Add(New ReportParameter("Param2", PARAM2))

        ReportViewer.ServerReport.SetParameters(reportParameters)
        ReportViewer.ServerReport.Refresh()
    End Sub

Now oddly enough the method doesn't get hit when I press the button a second time, I have tested by putting a break point in there.

I've tried adding EnableViewState="false" to my aspx but the ReportViewer throws and error saying it needs view state enabled.

3
  • Is that server report a drill-through one? What is the assembly version of Microsoft.ReportViewer.WebForms exist in your machine? Your current code seem to have no indication which lead to ViewState issue. Oct 31, 2018 at 9:16
  • @TetsuyaYamamoto - No I don't think it is a drill-through report. It sort of feels like an ftp, if I open the link in my browser and follow the report path it loads up in the browser without passing through another report. Apologies if my wording is incorrect.
    – Demonic218
    Oct 31, 2018 at 9:29
  • @TetsuyaYamamoto - Sorry for the late reply, I missed the question. The version i'm using Version 15.0.0.0
    – Demonic218
    Oct 31, 2018 at 11:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.