ContentPlaceHolder与Content控件
来源:互联网 发布:帝国cms标签调用大全 编辑:程序博客网 时间:2024/05/18 09:40
定义:
ContentPlaceHolder 控件:在 ASP.NET 母版页中定义内容区域。
Content控件:保存文本、标记和服务器控件以呈现给母版页中的 ContentPlaceHolder 控件。
两者关系:
ContentPlaceHolder 控件在母版页中定义相对内容区域,并呈现在内容页中找到的相关的 Content 控件的所有文本、标记和服务器控件。
Content 控件使用其ContentPlaceHolderID 属性与 ContentPlaceHolder 关联。将 ContentPlaceHolderID 属性设置为母版页中相关的 ContentPlaceHolder 控件的ID属性的值。
通俗的来讲,ContentPlaceHolder 控件是个容器控件,用来存放内容,但是如果它放在母板页中,那么它的内容页就需要使用Content控件来指定ContentPlaceHolder控件(好像一个指针一样,通过 ContentPlaceHolderID 属性来指定)来放置内容。
注意:
ContentPlaceHolder控件如果放在母版页中,那么它的内容页是通过Content控件来链接,是可编辑的。
但是Content控件如果放在母板页中,那么它的内容页中没有东西来对其进行链接,是不可编辑的。
举例:
母版页一的代码:
<head runat="server"> <title>演示</title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder></head><body> <form id="form1" runat="server">母版页演示 <div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </form></body>
母版页一的内容页的代码:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></asp:Content>
母版页二的代码(二级母版页,继承自母版页一):
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></asp:Content>
母版页二的内容页的代码:没有代码,是空白。
问题:这样的话二级母版页的内容页就不能进行编辑,如何解决呢?
解决:我们只需在二级母版页中添加ContentPlaceHolder控件即可。
举例:上面的母版页二,我们更改后:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"> </asp:ContentPlaceHolder></asp:Content>
母版页二的内容页变为:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server"></asp:Content>
- ContentPlaceHolder与Content控件
- 关于ContentPlaceHolder与Content控件
- 关于ContentPlaceHolder与Content控件
- ContentPlaceHolder
- .net2.0下ContentPlaceHolder控件下调用梅花语日期控件
- ASP 的Content控件
- asp.net 控件之content
- ASP.NET控件之Content控件
- ASP.NET控件之Content控件
- ASP.NET控件之Content控件
- Content-Encoding与Content-Type的区别
- ContentProvider 与Content Resolver
- springmvc与content-type
- Accept与Content-Type
- 在ContentPlaceHolder中注册onload事件
- 如何向一个控件中嵌入Content
- [J2ME]Content-Type与Post
- 关于content-type 与charsetencoding
- 大数取模
- 波兰式计算器
- Fibonacci数列问题
- 窗口更新机制
- 水王争霸
- ContentPlaceHolder与Content控件
- Android开发技术之──传感器使用
- 一个孩子的游戏
- 电话号码问题
- 孤独的运货员
- 小主教问题
- 获取操作系统版本(转MSDN)
- Android高手进阶教程(二十四)之---Android WebView的缓存!!!
- Red and Black