cancel
Showing results for 
Search instead for 
Did you mean: 

asp.net CrystalReportViewer paging problem

Former Member
0 Kudos

Issue: Cannot navigate past page 2. Seems very common with a lot of people having this problem.

There is at least 10 threads about this here and none of them have the answer.

The standard canned response is 'use Page_Init()'.

The situation is this:

  • All logic MUST BE IN Page_Load()!

There are several reason for this... I don't know the report name and parameters until the user selects them.

So I repeat. Page_Init is NOT AN OPTION.

I want to make this clear because none of the previous posters made this clear and got a ton of responses to use Page_Init() and they kept posting that they CANNOT use this event - just like me and people refusing to help them because the original poster won't use Page_Init().

It does work if I hardcode the report parameters OR pass the parameters to the page and use Page_Init()

I need it to work in Page_Load().

I have the following pseudocode based on code from here:

SAML Response from SAP Cloud Identity

protected void Page_Load(object sender, EventArgs e)

{

     if (Session["ReportDocument"] == null)

     {

          DataSet ds = new DataSet();

          // Get parameters from user , create datasource, etc etc.

          ReportDocument rpt = new ReportDocument();

          rpt.SetDataSource(ds);

          Session["ReportDocument"] = rpt;

          CrystalReportViewer.ReportSource = rpt;

     }

     else

     {

          ReportDocument rpt = (ReportDocument)Session["ReportDocument"];

          CrystalReportViewer.ReportSource = rpt;

     }

}

"next page" past page 2 still not working.

Can export to PDF, print, etc all work.

Selecting pages above 3 manually works.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

What version of VS and CR are you using? What is the patch level on CR?

Does this issue occur with all reports or specific reports.

Try upgrading to latest patch of CR and see if you could reproduce the issue.

Thanks,

Bhushan

Former Member
0 Kudos

Visual Studio 2015 and SP15.

Both are the latest.

Sorry about that not being in my original post.

Answers (1)

Answers (1)

former_member183750
Active Contributor
0 Kudos

Put your code in Page Init. Page load will not work.

google "Page init vs. Page load" for more details re. why / what / when.

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow me on Twitter

Got Enhancement ideas? Use the SAP Idea Place

Former Member
0 Kudos

I am perfectly okay with that if SAP says that's the only way this works.

It seems very limiting because how else would you get any parameters from the user?

So what your saying here is that you need two pages?

One to input parameters and the other to display the report.

There are no other workarounds to not use two pages for a report?

former_member183750
Active Contributor
0 Kudos

Not sure I understand the parameter "stuff". In most cases, when a report is fed a dataset (as is the case in your app) the dataset is already formatted to have the parameter based data in it. E.g.; CR should not be used to further filter the dataset. Maybe a typical work flow will help(?).

- Ludek

Former Member
0 Kudos

Well, the way I envision this working as do other posters is that you navigate to a page, say reports.aspx you have several choices.

For example, which report you want and the parameters for that particular report.

At this point you don't have a dataset because you don't even know which report your loading.

The user selects the report and the parameters such as a date range and clicks a button.

That posts back to the same page.

Now, if we do it in two pages it just gets clunky. the user has to go back to change parameters and run it again. What others including myself have been trying to get across is that the two page design, while works is very clunky to the user.

There surely has to be a way to make this work.

Something must be getting lost in the postback and if perhaps we knew what that something was we could preserve it in the session and restore it so we don't lose page navigation.

former_member183750
Active Contributor
0 Kudos

Sorry Mark, I'm not understanding why this would be a two page "thing". The way I would envision this is as follows:

1) Navigate to reports.aspx

2) Choose and rpt

3) Select parameters

4) Build dataset based on the selected parameters in (3)

5) Load report selected in (2)

6) Point the report at the dataset created in (4)

The above would be my preferred way. Now, I suspect the issue is in the implementation details of (3). In the above flow, you would not use the CR parameter input form. You'd have to create your own parameter input. If you are trying to use the CR viewer parameter form, then yes, you'd need a larger dataset that will hopefully have the data specified by the parameter. But then the whole workflow would change to:

1) Navigate to reports.aspx

2) Choose and load rpt

3) Point rpt at dataset

4) Refresh report - forcing a parameter prompt

5) Send report to viewer / export / print

I still do not see a two page thing happening here(?), or is the parameter prompt what you'd call the second page?

- Ludek

Former Member
0 Kudos

I am not sure I understand what your proposing.

We may be confusing terms - after all I am not a web person.

Reports in windows apps are a no brainer to me - they just work.. but we don't have all this loading and refreshing and stuff going on.

What I mean by two pages to get it working is this:

Page 1 selects the report and parameters then posts to page 2

Page 2 then loads the dataset based on those values and creates the report in page_init()

I am betting that this would work, since I have no problem getting the report to work properly when everything is done in page_init() and I already tested this by creating the second page and passing the parameters.

However.... doing it this way is not desired.

Now, the six steps you outline in the start of your answer is exactly what does NOT work.

( am assuming that you meant "choose a report" for #2?)

I am also not using any of the reports built in parameters. All parameters are used to generate the dataset for the reports.

This is how it's coded now. But you cannot navigate past page 2 unless you enter page 3, or 4, etc.

The code is in my first post. That's literally 3/4 of it except the SQL query stuff.

Don't know if this clarifies things or not.

Former Member
0 Kudos

Ok so I have some kind of workaround.

I embed the second page in the first.

No idea what rules I am breaking here since I am not a web person.

Code in first page:


<script runat="server">

                    void onIframeLoad(object sender, EventArgs e)

                    {

                        if (!IsPostBack)

                        {

                            reportiframe.Attributes.Add("onload", "this.style.height=this.contentDocument.body.scrollHeight +'px'; this.style.width=this.contentDocument.body.scrollWidth +'px';");

                        }

                    }

                </script>

                <iframe runat="server" id="reportiframe" src="ReportViewer.aspx" onload="onIframeLoad" frameBorder="0">

                </iframe>

All that stuff simply sizes the iframe to fit the Crystal Reports viewer.

Codebehind for the first page fires the second as such:


reportiframe.Src = "ReportViewer.aspx?Report=" + SelectedReport.Text + "&StartDate=" + txtStartDate.Text + "&EndDate=" + txtEndDate.Text;

Reportviewer.aspx is minimal with just the CrystalReportViewer.

The codebehind logic is all in Page_Init()

It works fine.

Still, can anyone from SAP explain why we have to resort to such hackery simply to get the next page button working?

For now I guess this will work... until someone tells me that it's a bad idea and talks me out of it.

Only tested in Chrome. Watch it not work in Edge or Firefox