Print Page | Close Window

Next page button not always working

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=2709
Printed Date: 28 Mar 2024 at 10:52pm


Topic: Next page button not always working
Posted By: livez
Subject: Next page button not always working
Date Posted: 26 Mar 2008 at 12:21am
I've created a report which I'm loading it into a CrystalReportViewer in Visual Studio 2005. When I run it though the next and 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. 
 
Has anyone else come across this problem and perhaps solved it?



Replies:
Posted By: BrianBischof
Date Posted: 26 Mar 2008 at 12:39am
Two things that you probably need to do. First, put the report loading code in the Page_Init() event. Second, save the report to the Session() colletion and then retrieve it from there when the page is reloaded (Page.IsPostBack). You don't want to recreate the report every time you go to a new page (thus losing track of your current page).

-------------
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>


Posted By: livez
Date Posted: 26 Mar 2008 at 12:54am
Hello and thanks for your reply.
 
I do save the document in a session, and load it into the viewer in page_load. I find it odd that it would work for page 1 and 2 and every other funktion requiring a postback working as well, and then suddenly when I want to go to page 3 it stops working.
 
Do you think moving it to Page_Init from Page_Load could solve it? I will try it, but I will have to do some modifications to the code.


Posted By: livez
Date Posted: 26 Mar 2008 at 1:56am
Problem remained :(. I´ve also noticed that this problem doesn´t occur when I run locally against the viewer in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\Crystalreportviewers12.
 
EDIT: I also noticed another problem that only occurs when I don´t run locally. When I click on a group I don´t get a NEW tab for the group, instead my old tab with "mainreport" is replaced.


Posted By: livez
Date Posted: 27 Mar 2008 at 5:13am
Thanks for your help, passing reportdocument in Page_Init instead of Page_Load solved it :)


Posted By: BrianBischof
Date Posted: 27 Mar 2008 at 7:57am
Glad it worked. The problem occurs because there is a timing problem with the Viewstate data and responding to mouse clicks in the Page_Load() event. But when you put the code in the Page_Init() event then this timing issue doesn't happen and your mouse clicks on the page navigation buttons will respond correctly.

I talk about this in Chapter 14 of my CR.NET books. You can find out more about my books at http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com or reading the http://members.crystalreportsbook.com - Crystal Reports eBooks online.

-------------
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>


Posted By: rean
Date Posted: 07 Apr 2008 at 12:09pm
I followed the steps in ur reply but still it is  not working.
the reports are displayed based on the invoice selection made in the list box and a textbox.
I databind  my crystal report in a little method called configure crystal reports, below is my pageinit method

protected void Page_Init(object sender, EventArgs e)

{

ConfigureListBox();

ConfigureTextBox();

ConfigureCrystalReports();

if (!IsPostBack)

{Session["InRept"] = InRept;}

else

{InRept = (ReportDocument)(Session["InRept"]);}

}

what am i missing?
any help wld be appreciated.
thanks in advance


Posted By: BrianBischof
Date Posted: 07 Apr 2008 at 10:01pm
First off, you can't use IsPostBack in the Init() event. This only works in the Page_Load() event. Secondly, you need to test if the Session["InRept"] = null and then call ConfigureCrystalReports(). Don't call it if it is already in the Session collection.




-------------
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>


Posted By: rean
Date Posted: 08 Apr 2008 at 9:52am

Brian,Thanks for replying,i did wht u suggested me to, but im still having problems. I have a textbox (where users can enter a invoice number and do a search) and a listbox which lists the invoice numbers.Evry time a make selection in the listbox or the search textbox the session for the report document "InRept" gets set to null, i dont know y its not persisting the session for the "Inrept". I have tried reorganizing my code but with no luck at all.Pls help



Posted By: robarahz
Date Posted: 07 May 2008 at 10:00am
Hi Brian,
 
I am having the exact same issue, but moving the report loading to the Page_Init() didn't help. Could I create the report in Page_Load() which it's currently doing, store it in session, then retrieve it in Page_Init()?
 
I'm thinking there's just too much code that doesnt' execute when it's in the page_init() event.
 
Thanks for any info.
 
-Robert


Posted By: BrianBischof
Date Posted: 07 May 2008 at 10:29am
I don't know why there would be code in the Page_Init() event that doesn't execute. That would be something necessary to debug. I guess your idea of initializing the report in the Page_Load() event would be okay as long as it's only done when the page loads the first time. But now you're putting similar code in two different events and there could be redundancy between them. Things start to get messy. I would think that if the Page_init() isn't executing code as expected, then the first order of business would be to debug this issue and then look at how to get Crystal working with your page.

-------------
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>


Posted By: robarahz
Date Posted: 09 May 2008 at 4:26pm
Sorry, oversight on my part. It works now.
 
Because I manually added the Page_Init(), I also had to wire it up in the InitializeCompnent() section. Once I did that, I could fire Page_Init(). I moved my code into there, and now my navigation buttons work!
 
Weird thing though, it seems as though Page_Init() fires more than once. It could be from my user controls though, not sure.
 
Thanks for the solution!
 
-Robert


Posted By: xxxxx
Date Posted: 12 Sep 2008 at 7:27am
hi guys

I had same problem and moving code to Page_Init() worked it out.

Here's a bit of my code in case you might need it.


Sub Page_Init()
        Try
            Dim abm As New abm
            ViewState("DataSet") = abm.returnDataSet("exec pviof.dbo.sp_printSelected '" & Request.QueryString("PVID") & "', '" & Request.QueryString("userName") & "' ")
            Dim r As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            r.Load(MapPath("PVIO.rpt"))
            r.SetDataSource(ViewState("DataSet").Tables(0))
            'charger le rapport
            CrystalReportSource1.Report.FileName = "PVIO.rpt"
            CrystalReportViewer1.ReportSource = r
            CrystalReportViewer1.DataBind()
            CrystalReportViewer1.Visible = True
        Catch ex As Exception
            ProcessException(ex)
        End Try
    End Sub


Posted By: jijogeorge
Date Posted: 11 Nov 2008 at 8:23pm
Hello,

I have created one crystal report, using viewer, in asp.net. And I have created a set of .rpt files for different reports. In my application I have one combo box to select the report types, and a command button to view the report. Based on the report type, the .rpt file will be loaded and assign to the  viewer.Everything is working fine, except two problems.
1) When I Click on next page, the report will go to 2nd page only, from second page its not loading the third page, the same thing happens for the previous button.
2) I'm using one formula filed, to pass the timezone difference in sends, and need to calculate the datetime, since in DB I am storing the datetime and seconds, in GMT. So when I bind a empty datset to the report, i an getting error like the specified column is unknow.

Or is there any good method to convert the dattime, stored in seconds, from GMT to end user's timezone ?


Waiting for your reply,

Thanks in advance



-------------
Jijo George
Software Engineer,
Bangalore, India


Posted By: robarahz
Date Posted: 12 Nov 2008 at 5:27am
Jijo,
 
For the buttons problem, refer to my post and the post of xxxxx above. If you move your report binding code from page_load to page_init in your aspx page, your buttons should work correctly.
 
I don't have an answer for your second issue, but I'm wondering if moving your data  retrieval and report binding to page_init() will take care of that problem as well.
 
Good luck.
 
Rob


Posted By: jijogeorge
Date Posted: 13 Nov 2008 at 1:35am
Thanks Rob,

The paging problem got solved and now I'm facing another problem.
I'm using the same aspx page to display various reports based on the user selection. the problem is when i generate one report and moved to 5th page, then i generated another report, which has more than 5 pages, the new report will show the 5th page. I have to click on 'show first page' to see the first page of the new report. I set ShowFirstPage() function while formatting the report viewer. the format function is calling fro  page_load event. The all the reports showing first page, but the navigation will not work properly. So can you tell me to resolve this issue?

Thanks in advance,


-------------
Jijo George
Software Engineer,
Bangalore, India


Posted By: robarahz
Date Posted: 13 Nov 2008 at 6:14pm
Hi Jijo,
 
I'm afraid I'm at a loss with this problem that you are having. You might try some of the Microsoft forums as well. Sorry and good luck.
 
Rob
 


Posted By: mwharton
Date Posted: 14 Nov 2008 at 11:01am
I am getting the same  issue using VB.NET
 
Page INIT
  configures crystal reporting
  pass parameters and report name, etc
  ya da ya da ya
 
  CrystalReportViewer1.ReportSource = crReportDocument
  Session("myReport") = crReportDocument
exit
 
 

Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

   Dim myReport As New ReportDocument

    If Page.IsPostBack Then

          myReport = CType(Session("myReport"), ReportDocument)

          CrystalReportViewer1.ReportSource = myReport

     End If

End Sub

 

 

 

 



-------------
Michael Wharton, MBA, PMP, MCDBA, MCSD, MCSE+I
www.WhartonComputer.com


Posted By: BrianBischof
Date Posted: 14 Nov 2008 at 11:09am

Michael, I'm confused by the code you posted. First off, you say you have code in the Page_Init() event (yada yada) but then you show code in the Page_Load() event for handling the report.

You should never put any CR related code in the Page_Load() event. This causes timing problems with loading viewstate data into memory and gives you headaches. Secondly, if you have code in the Page_Init() event, why do you also have code in Page_Load()? Remove this code and put everything in Page_Init().


-------------
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>


Posted By: ErikRic
Date Posted: 17 Dec 2008 at 1:12am
Originally posted by BrianBischof

Two things that you probably need to do. First, put the report loading code in the Page_Init() event. Second, save the report to the Session() colletion and then retrieve it from there when the page is reloaded (Page.IsPostBack). You don't want to recreate the report every time you go to a new page (thus losing track of your current page).


Hi, and thanks for getting me one step closer to a solution. I was wondering on a couple of things, though, since I am not very experienced with ASP.NET/Web development yet.

As I understand yoursolution (pseudo description):

Page_Init()
{
    report = SomeFactoryOrOtherCodeThatGeneratesReports();

    Session["reportId"] = report;
}

Page_Load()
{
     If(Page.IsPostBack)
     {
          report = Session["reportId"];
     }
}

I understand the point of not recreating the report, but won't this happen anyway since the Page_Init() fires every time?

Either way, just moving all the code from Page_Load() to Page_Init() seems to work, but I guess this may backfire in some way?


Posted By: Scott S
Date Posted: 08 Jan 2009 at 11:37am

What if you can not move all the code?  What specifically should be in the init?

I have three classes that are used to create one report so all the code in eacxh class can not be moved to the various init's.

Thanks

 
Scott


Posted By: jijogeorge
Date Posted: 11 Feb 2009 at 10:54pm
Hi,

I have one crystal report and m using crystal report viewer to display the report. The same report viewer is used to display other reports also, based on the report type selected by the user.
I have placed the report viewer inside a div and set the scroll properties

<td align="center" bgcolor="#FFFFFF" style="height: 415px;" colspan="4">
                            <div id="container" style="overflow: auto; width:100%;" >
                                <CR:CrystalReportViewer ID="iTocReport" runat="server" AutoDataBind="True"  ShowAllPageIds="True" Width = "100%" />   
                            </div>
                        </td>

The report works fine in Mizilla, the reports comes inside the div, and the div has scroll bars. The same report is not working proper in IE, the report going out of the div and looks ugly..

Can anyone suggest a solution for this?



Thatks in advance.


-------------
Jijo George
Software Engineer,
Bangalore, India


Posted By: kuldeep_sss
Date Posted: 24 Mar 2009 at 7:01pm
I am having problem with the next page button of the crystal report viewer, whenever i click on it, the page goes blank. I have a page where user selects a type of Table to be used, based upon this selection, a dropdownlist shows the entries for which report can be generated. On clicking the submit button report is generated and upto this place all works fine.  Whenevr i click on the next page button or any other button on the report viewer, the page goes blank, and if made the same search again, the next page in the report is shown.
    I have read about placing the code in Page_Init(), but as i make the data connection and the query based on the input of the user, will it help? How can i initialize the report document when it has to be generated based upon the user's choice? I am in a kind of fix.

Can anyone have a solution to it?

Thanks


-------------
Kuldeep Singh


Posted By: jijogeorge
Date Posted: 24 Mar 2009 at 9:26pm
Hi,
I also faced the same issue. but it rectified when i  shifted the code, to display the selected report, to page_init event. You can do the the formatting of reports in the page_load event. Check whether the enableviewstate (in .Net, actally you didn't mention your code behind language)property of report viewer and set it to true. Then i hope your problem will be rectified.
 


-------------
Jijo George
Software Engineer,
Bangalore, India


Posted By: kuldeep_sss
Date Posted: 25 Mar 2009 at 10:56am
The page_Init() method was not working properly in my case. May be because the report source is defined after the selection of the tables. I am using VB as the code language. I have solved this issue by using Session(). In the Page_Load() method i have checked if it is a postback or not. If it is a postback, the take the session() element of the report and assign it to the viewer.

Thanks for the help.



-------------
Kuldeep Singh


Posted By: manpakhong
Date Posted: 27 Mar 2009 at 1:27am

Problem: Crystal Report has issue a demonistration code to show that how to display Crystal Report embedded in ASP.NET web page. However, programmers always
confront problem that the code only display two page with the netvigator button. It cannot go beyond page if the report has.
file:///C:/Documents%20and%20Settings/dave/Local%20Settings/Temp/WindowsLiveWriter-429641856/supfiles2E440E/CaptureWiz021%5b5%5d.jpg -  
The main problem of this issue is that we always commit the wrong concept that we place the Report loading code over the Page_Load() instead of
Page_Init()

Two Main Points to solve the problem:
1. Load crytal report at Page_Init() instead of Page_Load()
2. Use Session in Page to store the report at Server, and load it back when Page is not postback

The Correct version:

protected void Page_Init(object sender, EventArgs e)
{
    if (!IsPostBack)
    {

    }
    else
    {
        mb_objcryRptDoc = (ReportDocument)Session["rptDoc"];   <-------------------------------------------------------Restore the report from Session for overcome the
                                                                                                         -------------------------------------------------------Page beyond page 3 problem.

    } // end if ... else (!IsPostBack)

    // ------------------------------------------------
    mb_fnInitFillAll();   <------------------------------------------------------ I load crystal report at this method

}

// #############
// # Page Load #
// #############
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        FS = FORM_STATE.INIT;
        ViewState.Add("FS", FS);
        mb_fnSetFormState(FS);

    }
    else
    {
        FS = (FORM_STATE)ViewState["FS"];
        mb_fnSetFormState(FS);

    } // end if ... else (!IsPostBack)

    // ------------------------------------------------
    // code to check user Login
    mb_objUserSession = new UserSession();

    if (!mb_objUserSession.pUser_Login)
    {
        Page.Response.Redirect("./frmUserNotPermitted.html");
    } // end if (!mb_objUserSession.pUser_Login)

    // code to check user permissions
    mb_fnCheckPermissions();
} // end Page_Load(object sender, EventArgs e)        

// #############
// #############                 

    /* *
     * method to init and fill all
     * */
    private void mb_fnInitFillAll()
    {
        mb_fnInit();

        // for user authentication
        mb_fnInitUserObject(); // vwrUserObject
        mb_fnInitUserGroupObject(); // vwrUserGroupObject

        if (Request.QueryString["Quotation_IDP"] != null && Request.QueryString["Quotation_IDN"] != null &&
            Request.QueryString["Quotation_IDR"] != null)
        {
            txtQuotation_IDP.Text = Request.QueryString["Quotation_IDP"].ToString();
            txtQuotation_IDN.Text = Request.QueryString["Quotation_IDN"].ToString();
            txtQuotation_IDR.Text = Request.QueryString["Quotation_IDR"].ToString();
            cbQuotation_ID.Checked = true;
            cbQuotation_ID.Enabled = false;
        }

        string strQueryString = "";

        if (Request.QueryString["URL"] != null)
        {
            strQueryString = Request.QueryString["URL"] + "?Quotation_IDP=" + txtQuotation_IDP.Text +
                "&Quotation_IDN=" + txtQuotation_IDN.Text +
                "&Quotation_IDR=" + txtQuotation_IDR.Text;
        } // end if (Request.QueryString["URL"] != null)

        if (Request.QueryString["URL2"] != null)
        {
            strQueryString += "&" + Request.QueryString["URL2"].ToString();
        } // end if (Request.QueryString["URL2"] != null)

        if (Request.QueryString["URL3"] != null)
        {
            strQueryString += "&" + Request.QueryString["URL3"].ToString();
        } // end if (Request.QueryString["URL3"] != null)

        this.hplBacktoQuotation.NavigateUrl=strQueryString;

        if (Request.QueryString["URL"] != null)
        {
            if (Request.QueryString["URL"].ToString().CompareTo("frmQuotationCMgt.aspx") == 0 ||
                Request.QueryString["URL"].ToString().CompareTo("frmrptQuotationC.aspx") == 0 )
            {
                txtQuotationType.Text = "cement";
            }
            else
            {
                txtQuotationType.Text = "tile";
            }

        }
        else
        {
            txtQuotationType.Text = "tile";
        }

        // ConfigureCrystalReports()
        ConfigureCrystalReports();          <----------------------------------------------------------------------------- I load Crystal Report here !

    } // end mb_fnInitFillAll()

/* *
 * Method to ConfigureCrystal Reports()
 * */
private void ConfigureCrystalReports()
{

    ConnectionInfo connectionInfo = new ConnectionInfo();
    connectionInfo.ServerName = mb_objConn.pstr_ConnString.pstr_server;
    connectionInfo.DatabaseName = mb_objConn.pstr_ConnString.pstr_initialCatalog;
    connectionInfo.UserID = mb_objConn.pstr_ConnString.pstr_userID;
    connectionInfo.Password = mb_objConn.pstr_ConnString.pstr_password;

    string reportPath = Server.MapPath("./reports/rptQuotation.rpt");

    ReportDocument rptDoc = new ReportDocument();

    rptDoc.Load(reportPath);

    cryRptVwr.ReportSource = rptDoc;

    //cryRptVwr.CssFilename = " http://localhost/crystalreportviewers115/css/default.css; - http://localhost/crystalreportviewers115/css/default.css";
    //cryRptVwr.ToolbarImagesFolderUrl = " http://localhost/crystalreportviewers115/images/toolbar/; - http://localhost/crystalreportviewers115/images/toolbar/";
    //cryRptVwr.GroupTreeImagesFolderUrl = " http://localhost/crystalreportviewers115/images/tree/; - http://localhost/crystalreportviewers115/images/tree/";

    SetDBLogonForReport(connectionInfo, rptDoc);

    // ---------------------------------------------------------------------------------------------------

    StringBuilder sbConnStr = new StringBuilder();
    sbConnStr.Append("Server=" + mb_objConn.pstr_ConnString.pstr_server + ";");
    sbConnStr.Append("uid=" + mb_objConn.pstr_ConnString.pstr_userID + ";");
    sbConnStr.Append("password=" + mb_objConn.pstr_ConnString.pstr_password + ";");
    sbConnStr.Append("initial catalog=" + mb_objConn.pstr_ConnString.pstr_initialCatalog + ";");

    SqlConnection sqlConn = new SqlConnection(sbConnStr.ToString());

    //SqlConnection sqlConn = new SqlConnection("Server=st;uid=sa;password=adminis;initial catalog=dbMRP;");

    // --------------------------------- vwrQuotation -----------------------------
    SqlCommand comd;
    comd = new SqlCommand();
    comd.Connection = sqlConn;
    comd.CommandType = CommandType.Text;
    comd.CommandText = mb_fnConcatenateSelect_Quotation();

    //comd.Parameters.Add("@Companyname", SqlDbType.VarChar, 50);
    //if (TextBox1.Text.Trim() != "")
    //    comd.Parameters[0].Value = TextBox1.Text;
    //else
    //    comd.Parameters[0].Value = DBNull.Value;

    SqlDataAdapter sqlAdapter = new SqlDataAdapter();
    sqlAdapter.SelectCommand = comd;

    DataSet ds = new DataSet();
    ds.ReadXmlSchema(Server.MapPath("./dataSet/dsQuotation.xsd"));

    sqlAdapter.Fill(ds, "vwrQuotation");

    //// ---------------------------------- SProductPrices ---------------------------
    SqlCommand comd2;
    comd2 = new SqlCommand();
    comd2.Connection = sqlConn;
    comd2.CommandType = CommandType.Text;
    comd2.CommandText = mb_fnConcatenateSelect_QuotationDItem();

    //comd.Parameters.Add("@Companyname", SqlDbType.VarChar, 50);
    //if (TextBox1.Text.Trim() != "")
    //    comd.Parameters[0].Value = TextBox1.Text;
    //else
    //    comd.Parameters[0].Value = DBNull.Value;

    SqlDataAdapter sqlAdapter2 = new SqlDataAdapter();
    sqlAdapter2.SelectCommand = comd2;

    sqlAdapter2.Fill(ds, "vwrQuotationDItem");

    //// --------------------------------------------------------------------------------

    //// ---------------------------------- SProductPrices ---------------------------
    //SqlCommand comd3;
    //comd3 = new SqlCommand();
    //comd3.Connection = sqlConn;
    //comd3.CommandType = CommandType.Text;
    //comd3.CommandText = mb_fnConcatenateSelect_SProductPrices();

    ////comd.Parameters.Add("@Companyname", SqlDbType.VarChar, 50);
    ////if (TextBox1.Text.Trim() != "")
    ////    comd.Parameters[0].Value = TextBox1.Text;
    ////else
    ////    comd.Parameters[0].Value = DBNull.Value;

    //SqlDataAdapter sqlAdapter3 = new SqlDataAdapter();
    //sqlAdapter3.SelectCommand = comd3;

    //sqlAdapter3.Fill(ds, "vwrSProductPrices");

    //// --------------------------------------------------------------------------------

    //rptDoc.Database.Tables["vwrQuotationD"].ApplyLogOnInfo(tableLogOnInfo);
    //rptDoc.Database.Tables["vwrSProductPrices"].ApplyLogOnInfo(tableLogOnInfo);

    cryRptVwr.ReportSource = rptDoc;
    rptDoc.PrintOptions.PrinterName = "Epson LQ-2170 ESC/P 2";

    System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
    printDocument.PrinterSettings.PrinterName = "Epson LQ-2170 ESC/P 2";

    for (int i = 0; i < printDocument.PrinterSettings.PaperSizes.Count; i++)
    {
        int rawKind;
        if (printDocument.PrinterSettings.PaperSizes.PaperName == "Fanfold 210 x 305 mm")
        {
            //rptDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize) printDocument.PrinterSettings.PaperSizes.RawKind;
            rawKind = Convert.ToInt32(printDocument.PrinterSettings.PaperSizes.GetType().GetField("kind", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(printDocument.PrinterSettings.PaperSizes));
            //crPrintOut.PrintOptions.PaperSize = rawKind;
            rptDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
        }
    }

    cryRptVwr.PrintMode = CrystalDecisions.Web.PrintMode.Pdf;

    rptDoc.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
    rptDoc.PrintOptions.PaperSource = PaperSource.Tractor;

    cryRptVwr.EnableParameterPrompt = false;

    // - SubReport rptProductionBatchD
    ReportDocument rptDocSub = rptDoc.Subreports[0];
    rptDocSub.SetDataSource(ds);

    //string strSubReportName = rptDoc.Subreports[0].Name;

    SetDBLogonForReport(connectionInfo, rptDoc);
    SetDBLogonForReport(connectionInfo, rptDocSub);
    //SetDBLogonForReport(connectionInfo, rptDocSub2);
    // - end Sub Report rptProductionBatchD
    cryRptVwr.ReportSource = rptDoc;

    cryRptVwr.Visible = true;

    mb_objcryRptDoc = rptDoc; // for handling the problem with crystal report deficit.
    // crystal report 11 The maximum report processing jobs limit configured by your
    // system administrator has been reached.

    //rptDoc.PrintToPrinter(1, true, 0, 0);

    Session["rptDoc"] = mb_objcryRptDoc;          <--------------------------------------------------------------------Remember to store the report at Session
} // end ConfigureCrystalReports

private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument _rptDoc)
{
    TableLogOnInfos tableLogOnInfos =
    cryRptVwr.LogOnInfo;
    foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
    {
        tableLogOnInfo.ConnectionInfo = connectionInfo;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in _rptDoc.Database.Tables)
        {
            table.ApplyLogOnInfo(tableLogOnInfo);

            //rptDoc.Database.Tables["vwrSupplierSProductSProductTypeAll_NoPrice"].ApplyLogOnInfo(tableLogOnInfo);
            //rptDoc.Database.Tables["vwrSProductPrices"].ApplyLogOnInfo(tableLogOnInfo);
        }
    }

} // end SetDBLogonForReport(connectionInfo connectionInfo)


Problem Solved:

file:///C:/Documents%20and%20Settings/dave/Local%20Settings/Temp/WindowsLiveWriter-429641856/supfiles2E440E/CaptureWiz022%5b3%5d.jpg -  

================================================================================================================================
The following is the code that it doesn’t overcome the problem:

// #############
// # Page Load #
// #############
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        FS = FORM_STATE.INIT;
        ViewState.Add("FS", FS);
        mb_fnSetFormState(FS);

        //Session["rptDoc"] = mb_objcryRptDoc;
        //// Restore Previous tbContainer.ActiveTab
        //if (Request.QueryString["tbContainer_ActiveTab"] != null)
        //{
        //    string str_tbContainer = Request.QueryString["tbContainer_ActiveTab"].ToString();

        //    switch (str_tbContainer)
        //    {
        //        case "tpPR":
        //            tbContainer.ActiveTab = tpPR;
        //            break;
        //        case "tpPRD":
        //            tbContainer.ActiveTab = tpPRD;
        //            break;
        //        default:
        //            tbContainer.ActiveTab = tpPR;
        //            break;
        //    } // end switch (str_tbContainer)
        //} // end if (Request.QueryString["tbContainer_ActiveTab"] != null)

    }
    else
    {
        FS = (FORM_STATE)ViewState["FS"];
        mb_fnSetFormState(FS);

        //mb_objcryRptDoc = (ReportDocument)Session["rptDoc"];

    } // end if ... else (!IsPostBack)

    // ------------------------------------------------
    // code to check user Login
    mb_objUserSession = new UserSession();

    if (!mb_objUserSession.pUser_Login)
    {
        Page.Response.Redirect("./frmUserNotPermitted.html");
    } // end if (!mb_objUserSession.pUser_Login)

    //// code to initial and bind all
    mb_fnInitFillAll();   <--------------------------------------------before I put Load Crystal Report function here

    // code to check user permissions
    mb_fnCheckPermissions();
} // end Page_Load(object sender, EventArgs e)

    /* *
     * method to init and fill all
     * */
    private void mb_fnInitFillAll()
    {
        mb_fnInit();

        // for user authentication
        mb_fnInitUserObject(); // vwrUserObject
        mb_fnInitUserGroupObject(); // vwrUserGroupObject

        if (Request.QueryString["Quotation_IDP"] != null && Request.QueryString["Quotation_IDN"] != null &&
            Request.QueryString["Quotation_IDR"] != null)
        {
            txtQuotation_IDP.Text = Request.QueryString["Quotation_IDP"].ToString();
            txtQuotation_IDN.Text = Request.QueryString["Quotation_IDN"].ToString();
            txtQuotation_IDR.Text = Request.QueryString["Quotation_IDR"].ToString();
            cbQuotation_ID.Checked = true;
            cbQuotation_ID.Enabled = false;
        }

        string strQueryString = "";

        if (Request.QueryString["URL"] != null)
        {
            strQueryString = Request.QueryString["URL"] + "?Quotation_IDP=" + txtQuotation_IDP.Text +
                "&Quotation_IDN=" + txtQuotation_IDN.Text +
                "&Quotation_IDR=" + txtQuotation_IDR.Text;
        } // end if (Request.QueryString["URL"] != null)

        if (Request.QueryString["URL2"] != null)
        {
            strQueryString += "&" + Request.QueryString["URL2"].ToString();
        } // end if (Request.QueryString["URL2"] != null)

        if (Request.QueryString["URL3"] != null)
        {
            strQueryString += "&" + Request.QueryString["URL3"].ToString();
        } // end if (Request.QueryString["URL3"] != null)

        this.hplBacktoQuotation.NavigateUrl=strQueryString;

        if (Request.QueryString["URL"] != null)
        {
            if (Request.QueryString["URL"].ToString().CompareTo("frmQuotationCMgt.aspx") == 0 ||
                Request.QueryString["URL"].ToString().CompareTo("frmrptQuotationC.aspx") == 0 )
            {
                txtQuotationType.Text = "cement";
            }
            else
            {
                txtQuotationType.Text = "tile";
            }

        }
        else
        {
            txtQuotationType.Text = "tile";
        } 
        ConfigureCrystalReports();   <--------------------------------------------------------- it appears here

    } // end mb_fnInitFillAll()

/* *
 * Method to ConfigureCrystal Reports()
 * */
private void ConfigureCrystalReports()
{

    ConnectionInfo connectionInfo = new ConnectionInfo();
    connectionInfo.ServerName = mb_objConn.pstr_ConnString.pstr_server;
    connectionInfo.DatabaseName = mb_objConn.pstr_ConnString.pstr_initialCatalog;
    connectionInfo.UserID = mb_objConn.pstr_ConnString.pstr_userID;
    connectionInfo.Password = mb_objConn.pstr_ConnString.pstr_password;

    string reportPath = Server.MapPath("./reports/rptQuotation.rpt");

    ReportDocument rptDoc = new ReportDocument();

    rptDoc.Load(reportPath);

    cryRptVwr.ReportSource = rptDoc;

    //cryRptVwr.CssFilename = " http://localhost/crystalreportviewers115/css/default.css; - http://localhost/crystalreportviewers115/css/default.css";
    //cryRptVwr.ToolbarImagesFolderUrl = " http://localhost/crystalreportviewers115/images/toolbar/; - http://localhost/crystalreportviewers115/images/toolbar/";
    //cryRptVwr.GroupTreeImagesFolderUrl = " http://localhost/crystalreportviewers115/images/tree/; - http://localhost/crystalreportviewers115/images/tree/";

    SetDBLogonForReport(connectionInfo, rptDoc);

    // ---------------------------------------------------------------------------------------------------

    StringBuilder sbConnStr = new StringBuilder();
    sbConnStr.Append("Server=" + mb_objConn.pstr_ConnString.pstr_server + ";");
    sbConnStr.Append("uid=" + mb_objConn.pstr_ConnString.pstr_userID + ";");
    sbConnStr.Append("password=" + mb_objConn.pstr_ConnString.pstr_password + ";");
    sbConnStr.Append("initial catalog=" + mb_objConn.pstr_ConnString.pstr_initialCatalog + ";");

    SqlConnection sqlConn = new SqlConnection(sbConnStr.ToString());

    //SqlConnection sqlConn = new SqlConnection("Server=st;uid=sa;password=adminis;initial catalog=dbMRP;");

    // --------------------------------- vwrQuotation -----------------------------
    SqlCommand comd;
    comd = new SqlCommand();
    comd.Connection = sqlConn;
    comd.CommandType = CommandType.Text;
    comd.CommandText = mb_fnConcatenateSelect_Quotation();

    //comd.Parameters.Add("@Companyname", SqlDbType.VarChar, 50);
    //if (TextBox1.Text.Trim() != "")
    //    comd.Parameters[0].Value = TextBox1.Text;
    //else
    //    comd.Parameters[0].Value = DBNull.Value;

    SqlDataAdapter sqlAdapter = new SqlDataAdapter();
    sqlAdapter.SelectCommand = comd;

    DataSet ds = new DataSet();
    ds.ReadXmlSchema(Server.MapPath("./dataSet/dsQuotation.xsd"));

    sqlAdapter.Fill(ds, "vwrQuotation");

    //// ---------------------------------- SProductPrices ---------------------------
    SqlCommand comd2;
    comd2 = new SqlCommand();
    comd2.Connection = sqlConn;
    comd2.CommandType = CommandType.Text;
    comd2.CommandText = mb_fnConcatenateSelect_QuotationDItem();

    //comd.Parameters.Add("@Companyname", SqlDbType.VarChar, 50);
    //if (TextBox1.Text.Trim() != "")
    //    comd.Parameters[0].Value = TextBox1.Text;
    //else
    //    comd.Parameters[0].Value = DBNull.Value;

    SqlDataAdapter sqlAdapter2 = new SqlDataAdapter();
    sqlAdapter2.SelectCommand = comd2;

    sqlAdapter2.Fill(ds, "vwrQuotationDItem");

    //// --------------------------------------------------------------------------------

    //// ---------------------------------- SProductPrices ---------------------------
    //SqlCommand comd3;
    //comd3 = new SqlCommand();
    //comd3.Connection = sqlConn;
    //comd3.CommandType = CommandType.Text;
    //comd3.CommandText = mb_fnConcatenateSelect_SProductPrices();

    ////comd.Parameters.Add("@Companyname", SqlDbType.VarChar, 50);
    ////if (TextBox1.Text.Trim() != "")
    ////    comd.Parameters[0].Value = TextBox1.Text;
    ////else
    ////    comd.Parameters[0].Value = DBNull.Value;

    //SqlDataAdapter sqlAdapter3 = new SqlDataAdapter();
    //sqlAdapter3.SelectCommand = comd3;

    //sqlAdapter3.Fill(ds, "vwrSProductPrices");

    //// --------------------------------------------------------------------------------

    //rptDoc.Database.Tables["vwrQuotationD"].ApplyLogOnInfo(tableLogOnInfo);
    //rptDoc.Database.Tables["vwrSProductPrices"].ApplyLogOnInfo(tableLogOnInfo);

    cryRptVwr.ReportSource = rptDoc;
    rptDoc.PrintOptions.PrinterName = "Epson LQ-2170 ESC/P 2";

    System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
    printDocument.PrinterSettings.PrinterName = "Epson LQ-2170 ESC/P 2";

    for (int i = 0; i < printDocument.PrinterSettings.PaperSizes.Count; i++)
    {
        int rawKind;
        if (printDocument.PrinterSettings.PaperSizes.PaperName == "Fanfold 210 x 305 mm")
        {
            //rptDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize) printDocument.PrinterSettings.PaperSizes.RawKind;
            rawKind = Convert.ToInt32(printDocument.PrinterSettings.PaperSizes.GetType().GetField("kind", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(printDocument.PrinterSettings.PaperSizes));
            //crPrintOut.PrintOptions.PaperSize = rawKind;
            rptDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
        }
    }

    cryRptVwr.PrintMode = CrystalDecisions.Web.PrintMode.Pdf;

    rptDoc.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
    rptDoc.PrintOptions.PaperSource = PaperSource.Tractor;

    cryRptVwr.EnableParameterPrompt = false;

    // - SubReport rptProductionBatchD
    ReportDocument rptDocSub = rptDoc.Subreports[0];
    rptDocSub.SetDataSource(ds);

    //string strSubReportName = rptDoc.Subreports[0].Name;

    SetDBLogonForReport(connectionInfo, rptDoc);
    SetDBLogonForReport(connectionInfo, rptDocSub);
    //SetDBLogonForReport(connectionInfo, rptDocSub2);
    // - end Sub Report rptProductionBatchD
    cryRptVwr.ReportSource = rptDoc;

    cryRptVwr.Visible = true;

    mb_objcryRptDoc = rptDoc; // for handling the problem with crystal report deficit.
    // crystal report 11 The maximum report processing jobs limit configured by your
    // system administrator has been reached.

    //rptDoc.PrintToPrinter(1, true, 0, 0);

    Session["rptDoc"] = mb_objcryRptDoc;
} // end ConfigureCrystalReports

private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument _rptDoc)
{
    TableLogOnInfos tableLogOnInfos =
    cryRptVwr.LogOnInfo;
    foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
    {
        tableLogOnInfo.ConnectionInfo = connectionInfo;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in _rptDoc.Database.Tables)
        {
            table.ApplyLogOnInfo(tableLogOnInfo);

            //rptDoc.Database.Tables["vwrSupplierSProductSProductTypeAll_NoPrice"].ApplyLogOnInfo(tableLogOnInfo);
            //rptDoc.Database.Tables["vwrSProductPrices"].ApplyLogOnInfo(tableLogOnInfo);
        }
    }

} // end SetDBLogonForReport(connectionInfo connectionInfo)


 manpakhong

mailto:manpakhong@hotmail.com - manpakhong@hotmail.com
mailto:manpakhong@yahoo.com - manpakhong@yahoo.com
 


Posted By: jijogeorge
Date Posted: 28 Apr 2009 at 12:12am
I'm developing  a web application, which consists of reports. The problem is that, while exporting the crystal report to msExcel format (not data only) I am getting one extra row after each record. This is not happening in the case of Excel- dataonly format. So can any of you help me out to resolve this issue.

-------------
Jijo George
Software Engineer,
Bangalore, India


Posted By: abubakar
Date Posted: 27 Jul 2009 at 10:30pm
Originally posted by BrianBischof

Glad it worked. The problem occurs because there is a timing problem with the Viewstate data and responding to mouse clicks in the Page_Load() event. But when you put the code in the Page_Init() event then this timing issue doesn't happen and your mouse clicks on the page navigation buttons will respond correctly.I talk about this in Chapter 14 of my CR.NET books. You can find out more about my books at
http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com
or reading the http://members.crystalreportsbook.com - Crystal
Reports eBooks online.


Hi, just wanted to thank, the solution of page init worked for me also! The OP asked the exact same question which i was about to ask but thought i should google first, so found this.

regards,

..ab


Posted By: abubakar
Date Posted: 27 Jul 2009 at 10:48pm
Originally posted by abubakar

Originally posted by BrianBischof

Glad it worked. The problem occurs because there is a timing problem with the Viewstate data and responding to mouse clicks in the Page_Load() event. But when you put the code in the Page_Init() event then this timing issue doesn't happen and your mouse clicks on the page navigation buttons will respond correctly.I talk about this in Chapter 14 of my CR.NET books. You can find out more about my books at
http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com
or reading the http://members.crystalreportsbook.com - Crystal
Reports eBooks online.


Hi, just wanted to thank, the solution of page init worked for me also! The OP asked the exact same question which i was about to ask but thought i should google first, so found this.

regards,

..ab


Posted By: abubakar
Date Posted: 27 Jul 2009 at 10:50pm
Originally posted by abubakar

Originally posted by abubakar

Originally posted by BrianBischof

Glad it worked. The problem occurs because there is a timing problem with the Viewstate data and responding to mouse clicks in the Page_Load() event. But when you put the code in the Page_Init() event then this timing issue doesn't happen and your mouse clicks on the page navigation buttons will respond correctly.I talk about this in Chapter 14 of my CR.NET books. You can find out more about my books at
http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com
or reading the http://members.crystalreportsbook.com - Crystal
Reports eBooks online.


Hi, just wanted to thank, the solution of page init worked for me also! The OP asked the exact same question which i was about to ask but thought i should google first, so found this.

regards,

..ab


In case any1 doesnt know how to write a page_init on the code-behind, plz look at the following page:
http://weblogs.asp.net/rajbk/archive/2006/01/16/Page-Event-handlers-in-ASP.net-2.0.aspx

regards,

..ab


Posted By: Ziya
Date Posted: 01 Sep 2009 at 11:20pm
Hi,
I did what you wrote. But still not working (display Session not found). Here is my code. Please correct my code if I wrong. Thanks in advance.
private void Page_Init(object sender, System.EventArgs e)
{
string str = (Request.QueryString["ds"]!=null) ? Request.QueryString.Get("ds").ToString():"";
if (Session[str] == null)                    
{
Response.Write("Session not found.");
return;
}
DataSet ds = (DataSet)Session[str];
rd.FileName = Server.MapPath(ReportFileName);
crv.ReportSource = rd;
rd.SetDataSource(ds);
crv.DataBind();
}



Posted By: xyron
Date Posted: 21 Jan 2011 at 2:13am
Hi member_profile.asp?PF=4&FID=9 - BrianBischof ,
 
I don't know if you have found the explanation, the solution in my case was to not put any code in page_load and use the page_init event instead.

  As the page_init event occurs once  the code should be implemented there.

If the page_load, all the code to generate the report is reinitialized each time the CrystalReportViewer controls are solicited.

I hope that helps. Smile
 
I just realized that the few last  posts of that discussion were concluding the same way as i do. Embarrassed

 



Print Page | Close Window