Session Values and Javascript?

S

savvy

I have a javascript menu navigation. I have some session values which
regularly get updated, but when i navigate using this Javascript menu
to a different page i'm not able to see the updated session values
where I actually need them, i will be getting only the old ones. And
when i refresh the page i can see the new values.
Is there is way to get around this problem?
Can any one help please?
 
M

Marina Levit [MVP]

I think what is more likely is that somehow the values are getting reset. It
doesn't matter if javascript or something else is doing the navigation - as
long as there is the same sessionid, you would see those values.

I would look at your code. My guess is that those values are getting reset
somehow to their 'old' values.

Also, I'm not sure what you mean by 'see' the new values. Are you displaying
these values on the page? Perhaps your pages are being cached by the browser
then.

If you are talking about on the server in the code, then I think it is the
case that something is resetting them.
 
V

Vadivel Kumar

Did you checked whether the sessions values are updated with the new
values? Please confirm that before doing anything.
 
S

savvy

Yes, I'm displaying the values on all the pages,Actually I'm developing
a shopping cart in which I'm displaying a small Item basket on all the
pages which displays number of Items added to the basket and their
total price on all pages.
So for example when I doing Response.Redirect to a Particular Page I
can see the updated values but when i navigate using this javascript
menu its just bringing up the old values ,
I can see that page is not posted back and I think its just bringing up
the cached page (I dont know much about caching! sorry). I think this
is pointing to the Caching Issue Problem
I'm not able to understand how to get over this problem. i've trying
this since 5 days till now
Thanks in advance for your time and help

code...

protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(Session["Total"]) == string.Empty)
{
pllogin.Visible = true;
plbasket.Visible = false;
}
else
{
pllogin.Visible = false;
plbasket.Visible = true;
lblquantity.Text = Convert.ToString(Session["TotQty"]);
lblprice.Text = Convert.ToString(Session["Total"]);
}
}
 
E

Eliyahu Goldin

Can it be a caching issue? To rule it out, try adding a random query
parameter to the url you navigate to in javascript.
 
S

savvy

Thanks everyone for your time
Contd...
Yes, I can see the values are updated and they are not resetted. lets
say in the main basket page if i change the no of items(quantity) so
the total price gets changes as well and these updated values are
supposed to be seen in all pages but if I use the JS Menu and navigate
to a particular page I can see the previous values only and if I
refresh the same page i can see the updated values.
Hope i made myself clear
So, if this is a caching issue how can i update the values in the
cache?

Thanks in Advance
 
S

savvy

Eliyahu Goldin, I dont know how to convey my thanks to u
it worked perfectly mate, i've been struggling to solve this problem
I didn't have got this trick
Thank u very very much
I can only wish with all my heart for your success in what ever u do
mate
Thank u very much for your time
 
E

Eliyahu Goldin

As I suggested in my other response, one of the ways to trick caching is to
add a random query parameter to the url. For example, instead of navigating
to abc.aspx, go to abc.aspx?<here is a random value>.

If you set url in javascript you can use the millisecond part of the current
time:
'abc.aspx?' + (new Date()).getMilliseconds()

If you set url on server side, you can use Random class or whatever else you
find for this matter.
 
E

Eliyahu Goldin

I can only wish with all my heart for your success in what ever u do

Thank you.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top