PageLoad

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I've run into a strange situation. It is my understanding that the Page_Load
event runs everytime the page is loaded. In my Page_Load event I have a
procedure that will populate a specific record.

I have a form that displays a listing of records. If you click on a record
the new page loads with that record loaded just fine. Now, on my target page
I have a save button that allows me to update an existing record and it works
fine. Now, when I close the form and return to the listing page it shows that
my update was processed correctly. Now, if I click on that same record again,
the Page_Load event does not run at all and somehow I end up getting the same
data for the record before I updated it.

If I go back to my list and click on another record the Page_Load event will
run.

It seems that once I click on a record it will run the Page_Load event the
first time, but the second and subsequent times it will not run the Page_Load
event and somehow it remembers the original values of which I am not setting
anywhere in code if the Page_Load event does not run.

I'm very puzzled and don't see how this can be happening. Is there something
in my url request string that would cause the Page_Load event not to run?

Any ideas would on why this may be happening would be helpful.

Thanks.
 
Greg said:
I've run into a strange situation. It is my understanding that the Page_Load
event runs everytime the page is loaded.

No, it runs every time the page is generated by the server. If it's cached
(client- or server-side) Page_Load doesn't fire.

You can work out the rest from there, really.
 
I found out why the "Page_Load" event wasn't firing all the time when loading
the page.

I was loading the page using a QueryString which would load the page and set
some QueryString variables to filter out a specific user. If I loaded a
specific record it would query my server and pull the data back. But, if I
close my data entry form and came back with the same QueryString it wouldn't
run the PageLoad event.

So, now instead of using QueryStrings I am using Session Variables and
everything works better and the Page_Load runs. Plus, using Session variables
seems to be much better anyways.

Thanks.
 
Greg said:
I found out why the "Page_Load" event wasn't firing all the time when loading
the page.

I was loading the page using a QueryString which would load the page and set
some QueryString variables to filter out a specific user. If I loaded a
specific record it would query my server and pull the data back. But, if I
close my data entry form and came back with the same QueryString it wouldn't
run the PageLoad event.
That's because a GET request that uses the same URL is subject to caching.
This is usually a Good Thing, but not always. There are mechanisms for
explicitly controlling the caching policies...
So, now instead of using QueryStrings I am using Session Variables and
everything works better and the Page_Load runs. Plus, using Session variables
seems to be much better anyways.
....but this is indeed often a better solution. Query string parameters are
trivial to tamper with and therefore require stringent validation, and you
need to use opaque values to hide sensitive or easily guessed security
parameters.

There are cases where putting information in the URL is better than using
the Session (when you actually *want* things to be cached outside of
sessions, for example), but those are a minority.
 
Back
Top