public variable does not keep it's value

  • Thread starter Thread starter nicholas
  • Start date Start date
N

nicholas

Got a public variable:
Public Dim i as integer

On page load the variable gets a new value
If at the end of my page load I have a response.write(i) , I can see the
value of i on top of the page (ex: 2)

Now, when I click my submit button and if I also place a response.write(i)
in the on click event, I get 0 and not 2 written on the page.

How comes?

THX
 
that's because ur page get posted back and your variable get reinitialized,
u can save ur value in ViewState in order to retain values during postback.

HTH
 
Is it always done in the page load.

Keep in mind that in a Web app the page is recreated for each HTTP request.
I.E. if you give a value in page load (let's say in a if not ispostback
block), the variable will nt be kept for the next http round trip....



Patrice
 
Back
Top