We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Applying Logic to Overwrite Cookies consecutively

rito1
rito1 asked
on
Medium Priority
555 Views
Last Modified: 2012-05-07
Hi All,

I am in the midst of creating a 'Last Viewed' cart function which in a nutshell records that last 2 products the user viewed.

I am creating this function using 2 cookies called - productID1 and ProductID2 which stores the database IDs of the product.

My problem is implementing the logic to create the cookies when on the product page...

I had the following IF statement in place initially (which I know is wrong) but to find that once 2 products have been viewed and both cookies have been created then the 3rd product the user looks at this should overwrite productID1 and the 4th product viewed should overwrite ProductID2 and so on and so on!

Please could anyone suggest how I could change the logic so that once both cookies are created, my code overwrites the first cookie and then second and so on...

Many thanks,

Rit

if (!Page.IsPostBack)
        {
            if (Request.Cookies["ProductID1"] == null)
            {
                // create cookie
            }
            else if (Request.Cookies["ProductID2"] == null)
            {
                // create cookie
            }
        }

Open in new window

Comment
Watch Question

Senior Developer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Cyber-spy, that is much appreciated indeed. Its spot on what I need!

Thanks,

Rit
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.