Asp.net control and ingress

Source: Internet
Author: User
1. Use Page. parsecontrol
2. Use base. loadcontrol
Part 1: load a template
The following is a template "<Table width = 100%> <tr> <TD width = 100% colspan = 2 runat = server id = containertop> </TD> </tr> <tr> <TD width = 30% runat = server id = containerleft> </TD> <TD width = 70% runat = server id = containerright> </TD> </tr> </table> "How to add it to the page.

first, you need to have a page (. aspx). There is a table with a row and a column in the page, and the server-side TD is named templatecontainer. Now, in the Code editing window, load the template in page_load.
Step 2: Use Page. parsecontrol analyzes the preceding HTML code as a web form page or user control system. web. UI. control the following code:
protected system. web. UI. htmlcontrols. htmltablecell templatecontainer;
system. web. UI. control objcontainer;
private void page_load (Object sender, system. eventargs e)
{< br> objcontainer = page. parsecontrol ("the above HTML code);
This. tempcontainer. controls. add (objcontainer);
}< br> the template has been loaded.
Part 2: loading a user control
first, determine the location where the user control is loaded to the page. Now you will find the first part of the HTML code, where every TD is a container you can find the container to load the control through page. findcontrol. The following code:
system. web. UI. control objcontrol = page. findcontrol ("containertop");
second, after finding the container, you can load your user control to the page. The following code:
objcontrol. controls. add (base. loadcontrol ("user control virtual path");
RUN Program to check whether the user control has been loaded.

The above are some of the main parts of dynamic loading templates and user controls. To make a good page, you still need to add many necessary things, for example, save the virtual paths of the template and user control to the database, and adjust the positions of the user control that has been loaded on the page. Permission control, such as those who can see what user controls those who can not see user controls, and so on.
Here is an example: http://elt.nec.edu.cn, but here you cannot adjust the location of the user piece. (Of course I can.) In this example, the navigation bar is also dynamically loaded. Different pages may use different templates to load different user controls.

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.