I have some Crystal Reports that I am using with my ASP .NET MVC application. I am using Session to get the data from the MVC controller to the WebForm.
My problem is that if I open report with one parameter values in one tab, and after that open it with different values, when I come back to the first one and export it, I get the values from the second.
I know that is happening because when I generate the second one, my session variable has that values. But why does not my tab keep the parameter values when that tab in chrome losts focus? Why it refreshes the data source for the report?
This is my MVC controller:
[HttpPost] public void iPregledStanaraPoZgradi(int idZgrade) { iRep = new Izvestaji.IzvestajiRep(); this.HttpContext.Session["repName"] = "CrystalReportPregledStanara.rpt"; this.HttpContext.Session["id_zgradePregledStanaraPoZgradi"] = idZgrade; }
This is my WebForm code for generating the report:
public void createRep() { try { bool isValid = true; string repName = HttpContext.Current.Session["repName"].ToString(); int zgradaID = (int)HttpContext.Current.Session["id_zgradePregledStanaraPoZgradi"]; if (string.IsNullOrEmpty(repName)) isValid = false; if (isValid) { int zid = zgradaID; ReportDocument rd = new ReportDocument(); string repPath = Server.MapPath("~/Izvestaji/") + repName; rd.Load(repPath); Izvestaji.IzvestajiRep irep = new Izvestaji.IzvestajiRep(); rd.SetDataSource(irep.PregledPoStanaruDS(zgradaID)); CrystalReportViewer1.ReportSource = rd; this.CrystalReportViewer1.ReuseParameterValuesOnRefresh = true; } else { Response.Write("<h2>Izvestaj nije pronadjen!</h2>"); } } catch (Exception ex) { Response.Write(ex.ToString()); } }