1

I need reportviewer control in my ASP.net MVC3 application. VS2010 ReportViewer V10.0

I tried using following solution. I created user control and put reportviewer control there.

How can I use a reportviewer control in an asp.net mvc 3 razor view?

Code is same as shown in above link.

The problem is, - if I hit next page or last page, it stays there only. - if I allow user to enter parameter and than click view report button on report viewer, it does nothing.

I know the reason, its losing its state. Its postback issue. If its regular aspx page i can control that in page_load by "!IsPostBack" but how to do that in user control. I tried putting IsPostback on control page_load but its always false.

My code is same as listed in above link. I am using user control.

Any solution?

Community
  • 1
  • 1
dhairya T
  • 11
  • 3

1 Answers1

2

This will do the trick and make IsPostBack=true on post back:

<script runat="server">
    private void Page_Init(object sender, System.EventArgs e)
    {
        Context.Handler = this.Page;
    }
</script>
shapkin
  • 99
  • 5
  • Please note it is for MVC. Postback, Page_init and similar web form concept not applies here. – Tariqulazam Oct 22 '12 at 00:08
  • The question was about using .ascx control in MVC application. It is possible to render .ascx control in MVC view via @Html.Partial("UserControlName"). But unfortunately, the IsPostBack is always false in the user control unless the above trick is applied. Page_Init is not valid in MVC, but it is valid in .ascx user controls. – shapkin Nov 14 '12 at 23:13
  • @shapkin Thanks, it helped me out with a page containing a report viewer which was an infinite loop of postbacks. – Candide Oct 31 '13 at 15:45