简体   繁体   English

创建并动态使用内容模板和控件

[英]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#. 我需要为网站内容创建动态模板,并在Asp.Net c#中动态加载.ascx控件。
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. 例如,我有一个空白的默认页面,并在其中动态加载存储在数据库中或仅存储在html页面中的html模板,然后在该html(比如div)中动态加载其他.ascx控件。

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. Joomla中使用了这种想法,您可以更改HTML模板和CSS,并对不同的子域使用不同的外观。

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. 通常,您将使用.NETs母版页来创建带有占位符的数据模板,然后从该母版页(或使用它的页面)动态控制占位符的哪些部分应显示哪些内容,要加载的控件等等。

Have a good look at masterpages http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx 仔细阅读母版页http://msdn.microsoft.com/zh-cn/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. 加载和添加逻辑当然取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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