Dynamically load the components of a user control! Three

Source: Internet
Author: User
Tags unique id
Dynamic | load | The previous article in the control writes to a simple application that dynamically loads a user control

Pages are used to browse the information! But more important is to interact with the user, according to different requirements to provide different content services, this is a service or a more user-friendly. (Talking nonsense again!) ^_^)

Dynamically loading the foliage, loading the content services that are not understood according to different user rights. The corresponding content service is loaded according to the user's corresponding load.

There is another application is to do the separation of the page and code. In Vs2003, a general ascx or ASPX file is directly associated with a CS file when it is first established. Then we can't do it separately while we're writing the program. Make the leaf and write back code can not be separated. In order to be able to do the work surface and the background code can be completely separate, we can be the background of all the code as a component to do it! Such a not with the CS file associated with the ASPX leaf file directly referencing a component can be! Then the component can load a different ascx file and finally make a complete leaf. The development of such a project is like a locomotive factory assembling different parts and there is a car coming out. Software can also be assembled, parts we can also order, and finally the whole can come out! (often see other people's article when how to think nonsense so much, the original found me a lot of nonsense!) ^_^)

Good! Let's start by step, and never need an aspx leaf associated with CS files! (in vs2005, when I create a new aspx leaf, I don't have a CS file associated directly.) But there is an incomplete type hidden. How to use the base class is a problem! The hidden part should have inherited page! Then according to the principle of single inheritance we cannot inherit other types. This question remains to be studied. )

According to the operation Principle of aspx leaf. The foliar interaction with the server must be done through a form tag in the run at server. So I don't want to write a form component first, then the form should be a container situation to host all the elements of the leaf that interact with the server (the container is too important, namespace can be considered a container, just can't put things, is a virtual container)

1, do form container formation: Inherit him on the line, pay attention to is a unique ID problem. I inherited the possibility of changing the ID, then back to the time can not find AH. Remember! Of course the render foliage is render by traversing all the components in the form container. So to change 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. UniqueID;

}

}

}



protected override void Renderattributes (HtmlTextWriter writer) {

This. Nonamecontainer = true;

Base. Renderattributes (writer);

This. Nonamecontainer = false;

}



protected override void RenderChildren (HtmlTextWriter writer) {

This. Nonamecontainer = true;

Base. RenderChildren (writer);

This. Nonamecontainer = false;

}



Private Boolean Nonamecontainer = false;

}

}





Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.