Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Next, Previous buttons not working for all pages Post Reply Post New Topic
Author Message
larryhack
Newbie
Newbie


Joined: 02 Oct 2007
Location: United States
Online Status: Offline
Posts: 2
Quote larryhack Replybullet Topic: Next, Previous buttons not working for all pages
    Posted: 02 Oct 2007 at 1:29pm

I've created a report which currently has 5 pages. I'm loading it into a CrystalReportViewer in Visual Studio 2005 (see code below). When I run it though the next & previous buttons don't work correctly. It goes to page 2 ok but after that it wont move to page 3. I can type in the page number and it will go to the right page. If I'm on the last page and select the previous button it goes all the way back to page 1. When I run the report inside Visual Studio 2005 next and previous buttons work fine. Any ideas?

public partial class _Default : System.Web.UI.Page {
 
private ListBox listBox;
  protected void Page_Load(object sender, EventArgs e){

  if (PreviousPage != null) {
    ListBox listBox = (ListBox)PreviousPage.FindControl("ListBox1");
    if (listBox != null) {
      
this.listBox = listBox;
      Session[
"report"] = this.listBox.SelectedValue;
    }
  }
  CrystalReportViewer1.ReportSource = (
String)Session["report"];
}

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 02 Oct 2007 at 2:14pm
Don't put CR code in the Page_Load() event. Use Page_Init().

Also, you need to save the report object to the Session() collection and then load it back from the Session() collection when Page.IsPostBack. Reloading the report from scratch on each page load is bad.


Edited by BrianBischof - 02 Oct 2007 at 2:15pm
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
larryhack
Newbie
Newbie


Joined: 02 Oct 2007
Location: United States
Online Status: Offline
Posts: 2
Quote larryhack Replybullet Posted: 02 Oct 2007 at 2:40pm
You da man Brian. That fixed it. Thanks so much.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.