views:

558

answers:

8

Hi All,

I am having a strange problem. Here is the scenario

Here are my files:

  1. Project1.aspx
  2. Project2.aspx

They are set up the exact same, including their Page_Load functions:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

If (Not Page.IsPostBack) Then

   setPrevIndex(-1)

   ...

   End If


End Sub

They are both set up this way.

Here is where I am running into a problem. When I navigate to either of these pages, i need to make sure that prevIndex is set to -1 (via the function).

  • For Project1.aspx when I navigate to the page, the Page_Load fires.
  • For Project1.aspx when I refresh the page, the Page_Load fires.
  • For Project1.aspx when I press "Go" in my browsers navigation bar, traveling back to the current page, the Page_Load fires.


  • For Project2.aspx when I navigate to the page, the Page_Load fires.
  • For Project2.aspx when I refresh the page, the Page_Load fires.
  • For Project2.aspx when I press "Go" in my browsers navigation bar, traveling back to the current page, the Page_Load doesn't fire at all! The function isn't even called.

Any ideas why??? What would cause this?

Please ask for clarification.

Update:

When I press "Go" in the URL pointing to the same URL, it seems like the masterpage is the only thing that re-loads, but the Load_Page event doesn't even fire...

Any other suggestions?

Thanks, E

+1  A: 

Try Setting the previndex to -1 in Page Init Event. I am not sure why this is happening though.

Eric
+3  A: 

Use LiveHTTPHeaders or Fiddler to make sure the page is actually being requested the same way each time. This may be an issue with caching.

Jeremy Stein
A: 

It sounds like your page is cached. This would cause the Page_Load not to fire. Check that you have not set that anywhere.

Alex
A: 

Have you tried publishing the application to a different machine? It could be IIS doing something so try and eliminate that first. Assuming that your code is identical in both na only the page names differ (do a diff on the aspx and .cs files to verify) then move your application to a different server and re-test.

If it is still occurring the it really must be your browser doing something probably with respect to caching.

Kelsey
A: 

Various cache-related things can cause the request not to be made, in particular when you merely press the "go" button, so you should check your cache-headers.

If caching is the issue, you can do something like:

//ask browser to revalidate:
context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
//and hint that the page is outdated anyhow...
context.Response.Cache.SetMaxAge(TimeSpan.Zero);

Which should convince a browser to really get a new version every pageview. You could, for instance, set these variables in the Page_Load itself ;-). If you're not using https, then the following are risk-free too:

//prevents plugin based file-open in IE+https, otherwise fine:
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();

I'll bet this solves it - and if not, I second Jeremy Steins suggestion that you use fiddler to verify that the request is really being made at all (and since you're a web-dev, get fiddler in any case, it's a handy tool to have available, and works for all browsers!).

Finally - can you tell whether any other code on the page runs when you click go? (i.e. is the entire page not running, or just Page_Load - the latter would suggest an event wire up error, which would be odd considering your load handler does sometimes fire).

Eamon Nerbonne
+4  A: 

Try disabling output cache and see if the problem still occurs:

<system.web>
  <caching>
    <outputCache enableOutputCache="false"/>
  </caching>
<system.web>
Richard Szalay
Thanks. Worked like a charm
Erik Ahlswede
Just remember to re-enable it on production ;) If you are not already using them, you should check out cache profiles (they can be configured/enabled individually). http://msdn.microsoft.com/en-us/library/aa661294.aspx
Richard Szalay
A: 

Try to recreate the scenario with stripped down functions on your server. If the problem persists, try to use some cache-countering methods. If not, that means it has to be your code.

gilbertc
+2  A: 

Load up your website locally and go to http://yourwebsite/trace.axd

This shows a server trace for each page, along with the server status. It also shows the complete page lifecycle with timings.

Clear the current trace and then repeat your 3 visits and reloads each to Project1.aspx and Project2.aspx

What does trace.axd show now? You should have 6 entries, each with the status code of 200 and the verb GET.

If you have fewer then your problem is caching of some sort.

If you have 6 then check the details for the last one - what does is show for the page event lifecycle? It will also show the complete WebForm control hierarchy, so if this related to the master page you will be able to tell.

Keith