2
votes

I want to dynamically create an ASP.NET report viewer web control, but got the exception below:

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

Below is my code:

    Microsoft.Reporting.WebForms.ReportViewer viewer = new Microsoft.Reporting.WebForms.ReportViewer();

    viewer.ServerReport.ReportServerUrl = "server url";
    viewer.ServerReport.ReportPath = "reprot path";

    System.Web.UI.ScriptManager scriptManager = new ScriptManager();
    Page page = new Page();
    System.Web.UI.HtmlControls.HtmlForm form = new HtmlForm();

    form.Controls.Add(scriptManager);
    form.Controls.Add(viewer);
    page.Controls.Add(form);

    page.DataBind();  //exception here

Any idea would be very much appreciated.

2

2 Answers

4
votes

Try adding the following tag to your aspx page:

<asp:ScriptManager id='scriptManager' runat='server' />
1
votes

Add this line inside the form tag on your ASPX Page

and must use IsPostBack on your page load to avoid infinite loop