Previous article writes a simple application of dynamically load user controls
The page is used to browse information! But more important is to interact with users, providing different content services according to different needs, this is a service or a more close to the user. (I am talking in a mess! ^ _ ^)
Dynamically load the leaves and load unknown content services according to different user rights. Deload the corresponding content service according to the user's corresponding content.
There is another application to be separated from the page and the code. In VS2003, general ASCX or ASPX files are associated with a CS file directly when they are just established. Then we can't do it separately when writing the program. Does not separate from the leaves and write background code. In order to be able to achieve the work surface and the background code can be completely separated, we can use all the code of the background as a component! Such an Aspx leaf file associated with the CS file is directly referenced by a component! Then the component can load different ASCX files to finally form a complete leaf. In this way, the development of a project is like a locomotive manufacturing plant, there is a car out of the car. Software can also be assembled, we can also customize, and finally it will come out! (Always see how many people's articles will feel nonsense, and I found that I have not nonsense! ^ _ ^)
it is good! Let's start with the Aspx leaves that do not need to associate CS files! (In VS2005, I don't have a CS file directly when I have built ASPX leaves. But there is no intact type hidden. How to use the base class a problem! The hidden section should inherit the Page! So according to The principle of single inheritance We cannot inherit the type. This problem needs to be studied.)
According to the principle of the Aspx leaf operation. The leaves must interact with the server must pass through a Run AT Server's FORM label. So I don't want to write a FORM component first, then Form should be a container's situation to carry all the elements that are interacting with the server, (the container is too important, Namespace can also be seen as a container, but not something Yes, it is a virtual container)
1. Do FORM container formation: Inherit him, pay attention to the problem of unique ID. You can inherit your ID, then you can't find it when you return. Remember! Of course, the render leaves are taken by traversing all components in all FORM containers. So to change the uniqueid.
Example:
Using system;
Using system.Web.ui;
Using system.Web.ui.webcontrols;
Using system.componentmodel;
Namespace region.controls {
Public class myform: system.Web.ui.htmlControls.htmlform {
Public Override string uniqueid {
Get {
IF (this.nonamecontainer && this.namingcontainer! = this.page) {
Return base.uniqueid.substring (base.uniqueid.lastIndexof (":") 1);
} else {
Return Base.unique;
}
}
}
Protected Override Void RENDERATITRIBUTES (HTMLTextWriter Writer) {
NonameContainer = True;
Base.rendrattributes (Writer);
NonameContainer = false;
Protected Override Void RenderChildren (HTMLTextWriter Writer) {
NonameContainer = True;
Base.renderchildren (Writer);
This. NonameContainer = false;
}
Private Boolean NonameContainer = false;
}
}
Last (continued)