session variables incrementing with a master page

T

TheAmes

Hi

VB.net 2.0 website developed with VWD 2005 Express


one masterpage
one content page aspx
and a global.asax


in the session start event of the global.asax file i declare a
session variable:


session("ItemCount") = 0


in the masterpage there is an asp:label


in the masterpage load event i put this:


label1.text = session("ItemCount").ToString()


on the content page (default.aspx) i have an imageButton. on the
onlclick event of the imagebutton i have this:


session("ItemCount") = session("ItemCount") + 1


HERES THE PROBLEM:


i press the image button, the page and masterpage reload, and the label

still says 0. BUT i press it again, everything reloads and it goes to
1. ress again and it goes to 2.


My question is, why doesnt it increment to 1 the FIRST time i press the

imagebutton?????


Thanks for your help


Ames
 
H

Hans Kesting

Hi
VB.net 2.0 website developed with VWD 2005 Express

one masterpage
one content page aspx
and a global.asax

in the session start event of the global.asax file i declare a
session variable:

session("ItemCount") = 0

in the masterpage there is an asp:label

in the masterpage load event i put this:

label1.text = session("ItemCount").ToString()

on the content page (default.aspx) i have an imageButton. on the
onlclick event of the imagebutton i have this:

session("ItemCount") = session("ItemCount") + 1

HERES THE PROBLEM:

i press the image button, the page and masterpage reload, and the label

still says 0. BUT i press it again, everything reloads and it goes to
1. ress again and it goes to 2.

My question is, why doesnt it increment to 1 the FIRST time i press the

imagebutton?????

Thanks for your help

Ames

If you put breakpoints at those two places where you work with that
session variable, you see that the "load" event is executed first (so
it will display the "old" itemcount) and *then* the click event is
executed (so the itemcount is incremented).

Solution: move the "label1.Text = .." statement to the PreRender event.

Hans Kesting
 

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

Top