473,508 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control Caching Issue

What I want to know is this: Is it possible to programmatically manipulate a
custom property of a user control for which <%@ OutputCache ... > has been
included? If so, then how? My brief code is at the end of this message.

The Microsoft documentation is a bit confusing to me. The following numbered
sentences appear in the .NET Framework Developer's Guide article titled
"Caching Portions of an ASP.NET Page":

1. You can declare an ID attribute in a user control tag that you have
specified for output caching in order to program against that instance of
the user control. However, you must explicitly verify the existence of the
user control in the output cache in order for the code to work properly.

This makes me think it is possible - provided that you verify the existance
of the user control.

2. If you write code to manipulate a user control that contains an @
OutputCache directive, an error will occur.

This makes me think it is NOT possible.

3. A user control that is output cached is dynamically generated only for
the first request; any subsequent requests are satisfied from the output
cache until the specified time expires.

This seems to be the explanation for sentence #2 listed above; but then the
next sentence (#4 below) makes me think it's actually possible.

4. Once you have determined that the user control has been instantiated, you
can programmatically manipulate the user control from the containing page.
You can include this logic in one of the page lifecycle events associated
with the user control, such as in the Page_Load event or the Page_PreRender
event.

What I have is a user control that implements a custom property. Everything
worked great until I decided to cache the control. I really need to cache it
for runtime performance reasons, and I really need to set the property value
from the calling page. Here's my code that set the user control's custom
property (Orientation) from the page_load event of the hosting aspx page.

1 Control menuControl = LoadControl("_Menu01.ascx");
2 ((__Menu01)menuControl).Orientation = 1; // 1 means vertical, 0 means
horizontal
3 MenuPlaceHolder.Controls.Add(menuControl);

I get the following error for line 2: Specified cast is not valid.

If I remove the caching directive from the ascx file (<%@ OutputCache
Duration="1" VaryByParam="none" Shared="true" %>), then the page and control
loads just fine.

Any ideas?

Thanks!


Nov 18 '05 #1
0 1306

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2428
by: DDK | last post by:
I am wondering how to go about caching a User Control for a set period of 24 hours starting at a certain time like 3am and lasting til 3am the following day. I know you can put the Output cache...
4
2431
by: Josh Harris | last post by:
Here is my question: It is common to have many pieces of business logic encapsulated within asp.net user controls. This can be found in high visibility projects such as the iBuySpy portal from...
2
1492
by: moondaddy | last post by:
My default page stays constant in the site and all the content in the body of the page is produced with user controls in a table cell for the body section. The main function of this site is a...
6
1454
by: Andrea Williams | last post by:
When I step through my code, the ASPX Page_Load happens before the Page_Load in the User Control. This means that the property values are not set to their defaults yet in the User Control and all...
1
2148
by: Barbara Alderton | last post by:
I have the following scenario: I have a user control that contains a registered menu control. The menu and other information on the user control is specific to the user accessing the site. ...
2
1247
by: Roshawn Dawson | last post by:
Hi All, I've decided to code a web user control that uses the ASP.NET Repeater control to render the output. This web user control obtains its data from a web service. If I were to use...
7
1932
by: Smithers | last post by:
I have a non trivial ASP.NET Web application that implements its navigation system via a user control (menu.ascx) placed on every page. It is important to note that the user control that hosts...
3
1670
by: fernandezr | last post by:
I have a navigation user control built using a sqlsitemap in our site's master page. After a user logs in the control doesn't refresh the data in the leftside navigation links. I found I can...
0
1450
by: helveticus | last post by:
I have a master/details configuration that includes multiple user controls. The details page is configured to cache data via VaryByCustom. This works fine. One of the user controls contains an...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.