简体   繁体   中英

Creating and dynamically using content templates and controls

I need to create dynamic template for my site content, and dynamically load .ascx controls in it in Asp.Net c#.
For example I have blank default page, and in it dynamically load my html template which is stored in database or just in html page, and then in that html (let's say div's) to dynamically load other .ascx controls.

I need this to load different site template for different user or domain, and with different widgets.

This kind of idea is used in Joomla, you can change your html template and css, and have different look for different subdomain.

Any ideas will be excellent.

In general, you'd use the .NETs masterpages to create the template with placehholders for data, and from that masterpage (or your pages that uses it), dynamically control which parts of the placeholders that should show what, which controls to be loaded and so on.

Have a good look at masterpages http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx

//Loading an .ascx dynamically is as simple as:
MyControlType myControl = (MyControlType)LoadControl("/location/MyControlType.ascx");
// and simply add it to the placeholders controls by
myPlaceHolder.Controls.Add(myControl);

The logic of what load and add is of course up to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM