473,783 Members | 2,354 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 programmaticall y 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 programmaticall y 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("_M enu01.ascx");
2 ((__Menu01)menu Control).Orient ation = 1; // 1 means vertical, 0 means
horizontal
3 MenuPlaceHolder .Controls.Add(m enuControl);

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="no ne" Shared="true" %>), then the page and control
loads just fine.

Any ideas?

Thanks!


Nov 18 '05 #1
0 1318

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

Similar topics

1
2446
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 directive in the User Control but I need the cache to be permanent, and I don't think you can make it permanent with the Output cache. Or can you? The User control has a datalist on it using a Sql Server database. So basically I just need to...
4
2447
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 MS. Virtually every bit of the site is encapsulated within user controls. The problem begins when you try to have user controls pass information to one another as well as to their parent form. This can be accomplished by creating public...
2
1510
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 products catalogue and the products show in a datagrid in one of the user controls. This datagrid has many rows and columns of images and this is what I'm most interested in caching. If I put <%@ OutputCache Duration="500" VaryByParam="MenuID"...
6
1467
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 the properties are blank. So my question is, where is the best place to put the code that handles the form. I was hoping to put it in the Page_Load on the ASPX page. Since the properties aren't available to the ASPX page at that point, I have...
1
2160
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. This user control is used on many pages. In order to create this control, I need to access information in the Active Directory to create both the menu and other info displayed on the control. This access takes some time and I wanted to cache this...
2
1259
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 fragment caching (<%@ OutputCache Duration="3600" %>) with this control, will it call the web service each time the page is requested or will it continue to use the web service data until the cache duration expires? I'd like to know as I'm trying to...
7
1943
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 the menu is injected into every page at runtime when the page is requested (i.e., it's not declared in any ASPX). The user control contains a menu that is dynamically populated and styled at runtime (fwiw: it's ComponentArt's Menu for ASP.NET -...
3
1683
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 force it to refresh if I simply resave one of the files in my project. These links then cache after I logout until I resave a project file again. How can I force the user control to refresh the data when a user logs in and logs out? Thanks,
0
1461
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 image button. With caching turned on, the control remains "lame" since the control is only dynamically generated during the first access. My understanding is that page caching directive causes all page user controls to be implicitly cached as...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
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 we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.