2

If you have a button and a text box in a page, and the page is cached on the server.
Put a breakpoint at page_load and run

If you click the button, the Page_load breakpoint is visited only for first click.

I am trying to get some explanation rather than "Wellll....ahhh mmmm it is a postback!!"
I am expecting that the breakpoint will not be visited at all, it is a cached page.

thanks

Costa
  • 3,897
  • 13
  • 48
  • 81
  • This is exactly the question I am browsing for. I created a test page, with output caching on with a button and a textbox. Clicking the button the first time puts new GUID A in the textbox. Clicking the button again results in the page being server from the cache until expiry. However, I don't quite understand why I ever got content in the textbox....Shame you didn't get an answer... – J M Feb 10 '12 at 19:21

1 Answers1

1

You need to use the VaryByParam opton in the @OutputCache directive. Include each of the submitted field names which specify a different version of the page. For example:

<%@ OutputCache VaryByParam="last_name;first_name" OtherAttributes="..." %>

This will cache a different version of the page for each combination of last_name and first_name in the posted data.

Ray
  • 21,485
  • 5
  • 48
  • 64
  • I don't see a relation between my question and ur answer, can u illustrate it please!! – Costa Apr 15 '10 at 13:35
  • Wow - ancient history :) I vaguely remember posting this answer, but it is pretty fuzzy. Anyway -- I would expect your breakpoint to get hit once, when the page is first generated, and then not again since it gets served from the cache. This seems to be the behavior you are describing. Please supply a little more detail on what you expect to happen compared to what is actually happening, and also post your cache directive. – Ray Apr 15 '10 at 14:12
  • I am coming again from ancient history, No, actually, when I open the page with my browser, the page is first generated and suppose to be cached, when I press the button, it is a post-back and therefore it is another request, the hit point should never be hit. do u follow me? – Costa Jun 17 '10 at 11:28
  • 1
    Does the bp get hit on the initial GET request? Or just after clicking the button? I believe that the cached page is considered to be different for a GET vs a POST. What code or directive are you using to cache the page? – Ray Jun 17 '10 at 23:09