Dynamically load the components of a user control!
Source: Internet
Author: User
Dynamic | load | Controls the purpose of our writing user controls is to put them in the page. Depending on the conditions, we can change the loaded user control!
In fact, the principle is the principle of masterpage. This masterpage will be available in vs2005, but it can now be implemented.
In my project, I use the following:
MasterPage on four classes, where the container dynamically loads the user control. This functionality will be ubiquitous in vs2005.
The following is a brief introduction to dynamically loading Foliar components:
All we need to do is change the address of the user component to dynamically change the loaded user component.
It's OK to change the Skinpath dynamically in the program.
Component source code is as follows:
Using System;
Using System.Drawing;
Using System.Collections;
Using System.Collections.Specialized;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.ComponentModel;
Using System.IO;
Using System.Web.Security;
Using Region.components;
Namespace Region.controls {
[ParseChildren (True)]
<summary>
page components, obtaining from the user component
</summary>
Public abstract class Skinnedcontrol:webcontrol, INamingContainer {
<summary>
User Component Name
</summary>
public string Skinfilename
{
Get
{
return skinfilename;
}
Set
{
Skinfilename = value;
}
}
<summary>
Component Name
</summary>
Protected string Skinname
{
Get
{
return skinname;
}
Set
{
Skinname = value;
}
}
<summary>
User component relative path and component name
</summary>
public string Skinpath
{
Get
{
return skinpath;
}
Set
{
Skinpath = value;
Skinfilename = value. TrimStart ('/');
}
}
}
}
For example, one of my applications:
Switch (context. PageID)
{
Case "1_1":
Base. Skinpath = "~/themes/signmanager/termlist.ascx";
break;
Case "1_1_1":
Base. Skinpath = "~/themes/signmanager/termedit.ascx";
break;
Case "1_2":
Base. Skinpath = "~/themes/signmanager/memberlist.ascx";
break;
Case "1_2_1":
Base. Skinpath = "~/themes/signmanager/memberedit.ascx";
break;
Case "2_1":
Base. Skinpath = "~/themes/signmanager/cardsend.ascx";
break;
Case "3_1":
Base. Skinpath = "~/themes/signmanager/membernoedit.ascx";
break;
Case "4_1":
Base. Skinpath = "~/themes/acountedit.ascx";
break;
Default:
Base. Skinpath = "";
Break
}
Based on the development of the formation, we can save a lot of the surface of the duplication of places. Just refer to the component at the place where the leaf is repeated.
Like what:
So that we can take the user component as the element, the component different foliage. Foliage can also be reused!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service