Caching dynamic controls in ASP.NET

Since the invention of partial caching in ASP.NET, we have been trying our best to implement it on our web pages. But without much luck. This post is a request, or I guess you could call it a “cry”, for help!

The problem is that we create all our controls dynamically, and each page can contain more than one instance of the same control (.ascx) but with different content.

Simply put, a page load is currently done like this:

  1. Retrieve a list of which controls to put on the page and the unique id of the content each control should display.
  2. For each control that should be created, call LoadControl and let the control know its unique id.
  3. Each control retrieves its data by using the unique id

Now, when trying to add partial caching to this control, the problem is that the controls are cached according to which page they’re on (or the query string used to get the page) and I just cannot figure out a way of caching two different instances of the same control. I mean, at the time of creation (LoadControl) I know which one I want, so it really should be theoretically possible, but I simply cannot find support for it in the API.

I’ve attached a simple test project that illustrates the problem. If you can find a nice solution, please, PLEASE let me know. I’d be in your debt!



One response to “Caching dynamic controls in ASP.NET”

  1. Hi,

    I had a look at the code-example quickly but couldn’t understand exactly what you are trying to achieve.

    But have a look at our post about similar subject.

    http://codeodyssey.se/blog.aspx?id=337 (in swedish)

    There are a few other links there that might be useful.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About Me

Consultant, Solution Architect, Developer.

Do note that this blog is very, very old. Please consider that before you follow any of the advice in here!

Newsletter

%d bloggers like this: