2 Replies - 709 Views - Last Post: 29 May 2017 - 01:58 PM Rate Topic: -----

#1 Dcurtis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-November 14

how to retrieve data from db and store in session?

Posted 16 May 2017 - 12:51 PM

Im trying to pass dynamic data from one page to another. User clicks an img and the img along with details about the img appear on another page and Im a little confused on how its going to work. All the information is stored in a db and was set up using entity framework 6 code first. Ive tried exposing the properties in my DTO and storing the info in session state then retrieve it on the other page:
  Product product = new Product();
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //get the information and store in session variable
            Session["PName"] = product.PName;
            Response.Redirect("~/DetailsPage.aspx");
        }
 //retrieve session state information
            if (Session["PName"] != null)
            {
                lblName.Text = Session["PName"].ToString(); 
            }



This has been unsuccessful so far. Im I on the right track or am I going about this the wrong way?

Is This A Good Question/Topic? 0
  • +

Replies To: how to retrieve data from db and store in session?

#2 Dcurtis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-November 14

Re: how to retrieve data from db and store in session?

Posted 16 May 2017 - 01:06 PM

asp.net webforms
Was This Post Helpful? 0
  • +
  • -

#3 WabiSabi  Icon User is offline

  • D.I.C Head

Reputation: 52
  • View blog
  • Posts: 224
  • Joined: 31-December 10

Re: how to retrieve data from db and store in session?

Posted 29 May 2017 - 01:58 PM

Where is your property getting set?

I'd suggest a break point at this line to see what, if anything is actually in there.

 if (Session["PName"] != null)


This works. I just took some existing code I'm working on and modified a bit to fit your question. I realize it won't all be done within the same method.

        HsoCreditReadyToWorkDTO product = new HsoCreditReadyToWorkDTO();

        protected void lBtnCancelAddCredit_Click(object sender, System.EventArgs e)
        {
            product.ProgramName = "TEST"; //are you setting the DTO property before trying to use it? can the calling code access the DTO?

            //get the information and store in session variable

            Session["PName"] = product.ProgramName; //is this code being called before the code that retrieves it? is session getting cleared before the code that retrieves it gets called?

            // Response.Redirect("~/DetailsPage.aspx");
            //retrieve session state information
            if (Session["PName"] != null)
            {
                lblNumberOfCredits.Text = Session["PName"].ToString();
            }

        }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1