Load content (user control and template) in ASP.NET

xiaoxiao2021-03-06  101

Load content (user controls and templates) in ASP.NET (User Controls and Templates) Points: 1. Use Page.Parsecontrol2. Using Base.LoadControl Part 1: Load Template Next is a template "

"How to add it to the page Medium.

First, you have a page (.aspx), there is a list of tables in the page, and the server-side TD we name it TemplateContainer. Well to go to the code editing window, load the template in Page_Load. Step 2, using Page.Parsecontrol to analyze the html code to analyze the top ML code as a web form page or user control system.Web.ui.Control as follows: protected system.web.ui.htmlcontrols.htmltablecell templateContainer; System.Web.ui .Control objContainer; private void Page_Load (object sender, System.EventArgs e) {objContainer = Page.ParseControl ( "top of the HTML code); this.TempContainer.Controls.Add (objContainer);} template has been loaded second portion. : Load User Control First, you have to determine the location of the user control to load to the page. Now you will find the first part of the HTML code, where each TD is a container. You can find you to load the control with Page.FindControl Container. As the following code: system.web.ui.control objcontrol = page.FindControl ("Containertop"); Second, after finding the container, you can load your user control into the page. As follows: Objcontrol.Controls .Add (Base.loadControl ("User Control Virtual Path")); Now running a program, is it loaded with a user control.

The above is some of the main parts of dynamically load templates and user controls. To do a better page, you need to add many necessary things. If you save the template and user controls in the database, the page has been loaded. The user control is adjusted. Control of permissions If those people can see what user controls can not see user controls, and so on. One of the following examples: http://elt.nec.edu.cn, but you cannot adjust the user position location here. (I can of course)) In this example, the navigation bar is also dynamically loaded, and different pages may use different templates to load different user controls.

转载请注明原文地址:https://www.9cbs.com/read-104570.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.056, SQL: 9