Is my logic correct on this page in terms of execute order?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: darrel (notreal_at_hotmail.com)
Date: 09/15/04


Date: Wed, 15 Sep 2004 17:39:54 -0500

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



Relevant Pages

  • Re: page_prerender...when/why to use?
    ... > You could catch PreRender and tweak the properties of each control - ... >>various controls read the cookie ... >>set the preference widgets to the default value ... But since the cookie isn't WRITTEN until the postback, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [PHP] base64-encoding in cookies?
    ... The sender is in the driver's seat and the receiver must follow suite. ... PHP application is usually what set the cookie in the first place. ... You have control over the value you insert into the cookie. ...
    (php.general)
  • Re: Delay AutoPostback?
    ... boxes even a 1 second postback "turn-around" can be annoying because it ... I have a set of check boxes (not many, but anywhere between 4 and possibly ... table and I regenerate/redisplay the table after each checkbox change. ... - Create a single control with an update panel containing one ...
    (microsoft.public.dotnet.framework.aspnet)
  • Control inside asp:Repeater generates ArgumentException: Invalid postback or callback argument.
    ... Invalid postback or callback argument. ... originate from the server control that originally rendered them. ... An unhandled exception occurred during the execution of ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Hidden Text Field Occasionally Missing Data on Postback
    ... by the ISP that were issued after the 1.1. ... 'Lets PreRender know that a control event caused postback ... for repositioning logic executed on the server postback. ...
    (microsoft.public.dotnet.framework.aspnet)