In .Net 1.x you can dynamically load user controls using the Page.LoadControl member. Providing you namespace your classes the same or qualify the classes correctly you can cast the return value of LoadControl to an object of your user control type.
MyUserControl myUserControl = (MyUserControl )LoadControl(“MyUserControl.ascx”);
MyFolderedUserControl myFolderedUserControl = (MyFolderedUserControl )LoadControl(“Folder/MyUserControl.ascx”);
Moving to .Net 2.0, where namespaces are no longer a key reference mechanism, an additional step is required.
In the partial code behind class, specify the loading and casting as you would in Net 1.x.
MyUserControl myUserControl = (MyUserControl)LoadControl(“MyUserControl.ascx”);
MyFolderedUserControl myFolderedUserControl = (MyFolderedUserControl)LoadControl(“Folder/MyUserControl.ascx”);
However, when you attempt to compile this code, the second line will fail, this is because the foldered user control is not part of the main assembly and the compiler knows nothing about it. To fix this you need to add a reference attribute to the aspx file that will host the user control:
<%@ Reference Control="Folder/MyUserControl.ascx" %>
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