How to cache different versions of a user control on the server

M

moondaddy

I have a user control that's used to display the products listing in the
main part of a page. This control is populated with a listing of products
from the database based on a category name passed into it via a function in
the code behind like this:
'Note, when we aren't looking at products, the product listing user control
gets switched out for a different user control such as aboutus.ascx or
something.

'This is a function in default.aspx code behind
Private Sub LoadProductsListing(ByVal sMenuID As String)
Try
Dim ctl As UserControl
ctl = LoadControl("Content/ProductListing.ascx")
'cellControlHolder is a table cell used to hold the user control
Me.cellControlHolder.Controls.Clear()
Dim ctlProd As ProductListing1 = ctl
'LoadMenu is a function in ProductListing1 codebehind that populates the
grid
ctlProd.LoadMenu(sMenuID)
Me.cellControlHolder.Controls.Add(ctlProd)
Catch ex As Exception
ErrLog(ex.Message, ex.StackTrace)
End Try
End Sub

So unlike a page that can have different versions cached based on the
parameters passed into the url, this user control get populated by calling a
function in its code behind from the parent page. Is there anyway to cache
a different version of this control for each product category?
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

From your description, your usercontrol has a certain member function which
can retrieve the data from database and construct the UserControl's actual
layout according to the input param, yes?

I'm afraid such situation is not suitable for using the asp.net 's caching
mechanism. Here are my understanding no this:
The asp.net's OutputCache(for both page or usercontrol) can depend on some
certain things such as request url's querystring , or some custom string
value , but all this dependence can be determined before the the page or
UserControl has been processed. For your scenario, the UserControl's cache
need to be dependent on a certain memeber function of itself. That means
its cache is will be determined after it's instanced and call certain
function. I don't think this suit the asp.net's buildin mechanism. Also,
here is a tech article describing the asp.net 's output caching mechanism.
You may have a look

#Page Output Caching, Part 1
http://msdn.microsoft.com/library/en-us/dnaspnet/html/asp03282002.asp?frame=
true

Also, if you have any new ideas, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top