.NETGURU
VaryByControl Caching problem w/ User Control & Properties
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcache' list.


Curtis Swartzentruber
-- Moved from [aspngfreeforall] to [aspngcache] by Marcie Jones <Click here to reveal e-mail address> --

Hi,

This might be better on the caching list or usercontrol
list, but not sure where. I have run into an issue that
appears to be caching-related as it only happens when
caching is enabled in my user control.

Here is the scenerio:

We run a music retail site, so a lot of content is based
on a particular genre. This is a perfect use for a user
control, with GenreID as a public property. First of all,
I want to make sure I am understanding the VaryByControl
param (can this be based on a public property of the control?)

Anyway, I am building a way to browse titles by genre and
obviously want to use caching since the paging and data
access can be expensive. I created a user control which
renders the "Sub Genres" of a particular Genre at the top
of a datagrid. If I try to cache this control, the first
time it is called it will render. If I browse to a new
GenreID, the call on that page fails with:

Object reference not set to an instance of an object.

at the point I am setting the GenreID property of the user
control. The same code works perfectly if I don't cache
the user control. Now I could probably use page level
caching to get around this, but I want to understand what
is going on.

Notes:

Main page is using VB code-behind
Control is using VB code-behind
Reference to user control is set in code-behind of main page
Property is being set in the Page_Load, using standard
    If Not Page.IsPostback

I'm curious if anyone can duplicate this problem. At this
point it seems to either be a misunderstanding on my part on
how to use varybycontrol caching or a bug.

Thanks,

Curtis

Reply to this message...
 
    
John Crim
AFAIK, you can't programatically set a property on a cached control,
because that control isn't actually created when cached output is used.
There probably is a way to do it, I just don't know how off the top of
my head.

However,
<TitlesUserControl Genre="xx" id="controlName">
Is legal. Genre must be a string property on the user control.

VaryByControl and VaryByParam do _not_ allow varying output by a
property of the control - they are both used to vary by the query string
or POST params. Additionally, VaryByControl allows you to cache output
for a specific user control name (id).

Regards,

John Crim
WebGecko Software
http://www.webgecko.com

-----Original Message-----
From: Curtis Swartzentruber [mailto:Click here to reveal e-mail address]

We run a music retail site, so a lot of content is based
on a particular genre. This is a perfect use for a user control, with
GenreID as a public property. First of all, I want to make sure I am
understanding the VaryByControl param (can this be based on a public
property of the control?)

Anyway, I am building a way to browse titles by genre and obviously want
to use caching since the paging and data access can be expensive. I
created a user control which renders the "Sub Genres" of a particular
Genre at the top of a datagrid. If I try to cache this control, the
first time it is called it will render. If I browse to a new GenreID,
the call on that page fails with:

Reply to this message...
 
 
System.Web.UI.Page




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification