views:

2291

answers:

4

I'm trying to render the report viewer programmatically within a custom Page placed in an IHttpHandler context

ReportViewer rv = new ReportViewer();
ReportDataSource rds = new ReportDataSource();
rds.Name = "Report";
rv.LocalReport.ReportPath = "Report.rdlc";

rds.Value = SomeReportObject;

rv.LocalReport.DataSources.Add(rds);
rv.LocalReport.Refresh();

ScriptManager scriptHandler = new ScriptManager();
MyPage p = new MyPage();
p.Controls.Add(scriptHandler);
p.Controls.Add(rv);

using (TextWriter myTextWriter = new StringWriter())
        {
            using (HtmlTextWriter myWriter = new HtmlTextWriter(myTextWriter))
            {
               p.RenderControl(myWriter);
            }
        }

Although I have the ScriptManager added to the page but the runtime complains that the ReportViewer needs one, it throws the following exception at p.RenderControl(myWriter) line

The Report Viewer Web Control requires a System.Web.UI.ScriptManager on the web form.

And this is the MyPage Class

public class MyPage : Page
{

    public override void VerifyRenderingInServerForm(Control control)
    {
        //Empty Method
    }

    public override bool EnableEventValidation
    {
        get { return false; }
        set { /* Do nothing */}
    }
}

Any help would be very appreciated. This is done on .NET 4 and I'm using ReportViewer 2010.

Many thanks,

Maya.

+1  A: 

just drag on the ScriptManager control under AJAX Extensions and it should work

ScaleOvenStove
You probably need to read the question's details not just the title.
Maya
A: 

Hi Maya,

Did you ever get this working?

I need to do the same thing and can't work out how to do it...

Any help would be much appreciated ;)

Cheers!

Tod.

c0ntinuum
No, not yet, for the time being I had to disable the internal AJAX calls to get the report rendered smoothly, I had to go with the ugly full post back to get this done. I'm still desperately looking for a solution here. Let me know if you get one before you lose your enthusiasm!
Maya
I've put that one in the "too hard basket" for now - but I'll have to get back to it before the end of the month - so I'll let you know what I find out ;)
c0ntinuum
A: 

In the aspx:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <rsweb:ReportViewer ID="rptViewer" runat="server" Width="100%">
    </rsweb:ReportViewer>
</form>  

It worked for me, so I hope it helps everyone.

Sergio
Another answer where people don't read the question.
Maya
A: 

Sorry to not contribute anything, but I'm running into the same incredibly frustrating issue. Any resolution?

related questions