Cookie not set fast enough

G

Guest

I have an application that sets a cookie through a class. I set it in a push
button event on a postback. When the page reloads, a user control checks the
value of that cookie to display name information. The problem is - the
cookie is not being set fast enough for the user control to find it. Can you
offer any solution?

Thanks,
Denise
 
C

Curt_C [MVP]

Denise said:
I have an application that sets a cookie through a class. I set it in a push
button event on a postback. When the page reloads, a user control checks the
value of that cookie to display name information. The problem is - the
cookie is not being set fast enough for the user control to find it. Can you
offer any solution?

Thanks,
Denise

Huh? I dont think that's possible. If it's linearly executed code its
not possible. Are you sure there isn't a potential issue elsewhere?
Perhaps cookies aren't allowed, not set properly, not called properly, etc?
 
M

Marina

I am guessing you have a user control on the same page as the button, and
you are looking for this in the user control's Load event? In which case,
the button's Click event is going to run after the Load event of the user
control (and the page this is all on for that matter).

You need to restructure the way your page communicates with the user control
and when you are pulling information out.
 
G

Guest

It is happening - but not all the time. If I step through the code, it works
as expected. It works fine 80% of the time, but there are other times when
it pulls the prior cookie and reloads the wrong row.

private void NewButon_Click(...)
{
HttpCookie Cookie = new HttpCookie("CaseId", 0);
HttpContext Current.Response.Cookies.Add(Cookie);

LoadData();
}

private void LoadData()
{
HttpCookie Cookie = HttpContext.Current.Request.Cookies["CaseId"];
///Sometimes Cookie is equal to the prior cookie set !!!!
}

Actually, I was setting the cookies in a separate class using the
HTTPContext. When I tried pasting it directly into my code, I was using
Response.Cookies, but both seemed not to work well.
 
G

Guest

Yes, that is happening as well...I have one case where the user control is
loading before the cookie has been set, but that is not the problem I am
having. See above post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top