I've been struggling with a page that is set up like this:
PAGE:
------------------
control 1 - reads a cookie and executes stuff based on that
control 2 - reads the same cookie and can also set the value
------------------
So, the logical layout for control 2 was this:
CONTROL 2:
-------------------
on page_load
- read the cookie
- based on the cookie, set the form values to match the current cookie
on buttonClick
- set the cookie to the new value
-------------------
The problem is that I *think* CONTROL 2 is executed in this order:
page load (do stuff)
button click
postback
page load (do stuff)
button click even handler (do stuff)
is that correct? If so, the issue is that the postback page reads the cookie
before setting it, so it's always one 'page view' behind.
My solution was to do the following. It works, but I'm wondering if I'm
completely not getting something obvious:
CONTROL 2:
-------------------
on page_load
if postBack
- set the cookie to the new value
- redirect to this page
else
- read the cookie
- based on the cookie, set the form values to match the current cookie
end if
on buttonClick
- do nothing but trigger the postback
-------------------
The logic being that I'm doing a postback to set the cookie, then a complete
refresh to then read the new setting. I'm only loading the page once in the
browser, but the server reads it twice.
I've had this similiar question before and came to conclusion that this is
about the best method. But before I get too set in my ways, I thought I'd
double check with the masses. I should note that I don't want to use any
javascript.
-Darrel