Linked .Net Users Group

VaryByParam="__EVENTARGUMENT"


OutputCache is magical but sometimes can be frustrating unless you know what is really going on.


 I spent all day trying to understand what was going on and why was I not able to get to the server while using OutputCache and setting it up with my BulletedList's ListItems.

If you View Source on the web page, you will see the Javascript function below:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }

__doPostBack is a magical function to those who have not yet understood what it does and why it's there.

This baby will SET the hidden field, shown below, with the value you are trying to POST back to the server.

<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

Normally, the Form will POST the name/value of the inputs fields in the Request.Form object as keys - However, the __doPostBack will use the __EVENTARGUMENT as the Name of the Key to store the value.

This solves any caching issues when dealing with controls that do not render as input fields like the asp:TextBox.
 
Posted by Dimitri Nikolaros on 5/29/2009 6:35:29 PM


Current rating: 0 (0 ratings)

Bookmark this page to:Add to Yahoo Bookmarks Add to Facebook Add to Ask Add to Blogmarks Add to Simpy Add to MyAOL Add to Delicious Add to Multiply Add to Link-a-Gogo Add to Faves Add to Twitter Add to Live Add to Furl Add to Mixx Add to Magnolia Add to Segnalo Add to Reddit Add to Terchnorati Add to StumbleUpon Add to Digg Add to Slashdot Add to Spurl Add to Yahoo MyWeb Add to Newsvine Add to MySpace Add to Diigo Add to Backflip Add to Mister Wong Add to Google Bookmarks

Comments
alessandro
hey!! Right, facinating how output caching can get limiting at some point when your needs get complex.

NEVER understimate the powers of .NET (everythings possible). You just have to start thinking out of the box.

This is indeed a neat trick i shall be bookmarking. Thanks for sharing.
5/29/2009 7:24:20 PM
 
alexp
Great help!

I was trying to figure out how to take advantage of the output cache varybyparam option, and I thought that microsoft documentation was somewhat unclear as to how to apply this to a case specific scenario.
5/30/2009 11:13:19 AM
 
efdee
Looks like a good solution for your problem. I'm a tad bit worried about what happens if you have 2 different controls that post back the same value. Wouldn't the second control get the page that was originally cached because of the first control?

I assume this is not a problem when your page has only one control, but it might introduce weird behavior later on.
5/30/2009 6:22:44 PM
 
dnikolaros
@efdee

I agree with you. This is a solution to a specific situation where I expected a lot of page views on a simple page containing a GridView and a BulletedList control.
5/30/2009 11:11:59 PM
 

Sign in


Shortcuts

Latest blog comments

5/29/2009
alessandro
hey!! Right, facinating how output caching can get limiting...

5/30/2009
alexp
Great help! I was trying to figure out how to take advan...

5/30/2009
efdee
Looks like a good solution for your problem. I'm a tad bit ...

5/30/2009
dnikolaros
@efdee I agree with you. This is a solution to a specifi...

Post archive

May 2009(1)
 
This web site uses Kentico CMS, the content management system for ASP.NET developers.