If you are using the @ OutputCache directive on a user control that you are adding programatically you will not receive a reference to the control type directly when you ‘LoadControl’. Instead you will be returned an object of type PartialCachingControl.
The CachedControl property is not hugely intuitive, it’s actually set when the object is cached the first time – it’s the property saying, “By the way, I’ve cached this object for you, just so you know”. If the object is already in the cache the CachedControl property returns null, this time it’s saying, “I haven’t had to cache anything as it was already in the cache”.
If you do not add the PartialCachingControl to the control tree the CachedControl property will ALWAYS return null.
Here is a simple routine that demonstrates this:
void Page_Init()
{
Control Item;
Item = Page.LoadControl(“test1.ascx”);
Test1a.Controls.Add(Item); // Comment this line to see the “always null” behavior.
if ( ((PartialCachingControl)Item).CachedControl != null)
{
Response.Write(“CachedControl is not null! – Control was not in the cache but is now “);}
else
{
Response.Write(“CachedControl is null! – Control was already in the cache”);}
// To obtain a reference to your object access the control collection (Alternatively you can use ‘FindControl’)
MyUserControl myControl = (MyUserControl) Item.Controls[0];
}
AI Assistance in Microsoft Fabric
The exponential growth of Large Language Models (LLMs) couples with Microsoft’s close partnership with OpenAI
Apr
10 reasons why it’s worth the effort to understand the value of your data
“If leaders really want to create a data driven culture, the journey starts with them!
Apr
Content Safety in Azure AI Studio
Azure AI Content Safety is a solution designed to identify harmful content, whether generated by
Apr
Model Benchmarks in Azure AI Studio
In the constantly changing field of artificial intelligence (AI) and machine learning (ML), choosing the
Apr
Celebrating International Women’s Day: from Classroom to Code
As we celebrate International Women’s Day, I want to share my journey of breaking stereotypes
Mar
Pretty Power BI – Adding Pagination to Bar Charts
Good User Experience (UX) design is crucial in enabling stakeholders to maximise the insights that
Feb
Pretty Power BI – Creating Dynamic Histograms
Good User Experience (UX) design is crucial in enabling stakeholders to maximise the insights that
Feb
Top Tips to Pass the Databricks Certified Data Engineer Professional Exam
Having recently passed the Databricks Certified Data Engineer Professional exam, this blog post covers some
Jan