Sessions vs. Cookies?

Discussion in 'ASP.NET / ASP.NET Core' started by Karen, May 27, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I've read online tutorials about sessions, but I haven't found the specific answer to this question...

    In one page, I have a user fill out their name, address, phone number, etc. into textboxes. When they click submit, their info is emailed to me and an email is sent automatically to them.

    I have several pages that require the same information that the user can fill out and make requests from. After the user has entered their information once on PageA.aspx, I'd like the same boxes on other pages to retain that information. So, if the user fills out PageA.aspx and clicks submit, when he visits PageB.aspx, I'd like his information to already be in the boxes, simply waiting for him to click submit again. And, if he happens to visit PageB.aspx first (or PageC.aspx or whatever), I'd like that information to be waiting on PageA.aspx or PageH.aspx. And, I'm redirecting to an entirely different response page.

    This seems like it has to be easy to do, but I haven't had any luck with it. I've tried the Server.Transfer option (which uses Context.Item), but the pages I want the information to populate toare not the same page I want them to see when they click submit.

    Thanks in advance!

    ~Steph
     
  2. Steph,

    The best way to do that is to put the info in a cookie. In the event handler for the Submit button(s),create a new cookie object, add the textbox values to the cookie (cookies use a name-value pair to store data), then attach the cookie to the response stream.

    Now in the page_load of each of the pages, check the request object for the cookie and if it is present, retreive the data and put it back into the textboxes.

    If you have a submit button on each of the pages, add some logic to replace instead of add the cookie to theresponsestream if it is already attached to therequest object.

    This is the simple way to do it. More elegant solutions are below:

    Solution 1:
    If your pages are part of a "wizard", you may want to consider combining all of the pages into a single page. You can place thecontent that differs from page to page into separate panel containers. Use the visible property of the panels to control what is rendered to the client. To keep track of which "step" the user is on, create a session-backed integer property that can be incremented and decremented as the user moves through the wizard.

    A session-backed property looks like the following:

     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page