【ASP.NET Step by Step】之三 Master Pages and Site Navigation
主页面:
<div id="content">
<asp:contentplaceholder id="MainContent" runat="server">
<!-- Page-specific content will go here
![](https://yuyijq.cnblogs.com/Images/dot.gif)
</asp:contentplaceholder>
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
新建的页面:
Default.aspx
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
2. 站点地图,是一个XML文件,每次添加删除了页面,要更改这个文件
可以用下面这些标记将站点地图绑定到Menu控件中:
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
3. Reapter控件的使用,当将SiteMapDataSource绑定到Repeater时,会自动遍历。
因为SiteMapDataSource控件的ShowStartingNode属性被设为false,所以从站点地图的第二级节点开始。
使用嵌套,第一层绑定站点第二级,第二层绑定站点第三极:
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
7
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
20
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
28
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
29
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
这两个Repeater生成的HTML标记(为了节省篇幅一些标记被移除了):
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://yuyijq.cnblogs.com/Images/dot.gif)
22
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://yuyijq.cnblogs.com/Images/dot.gif)
28
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
4. 因为我们使用了这样的CSS
#navigation {
width: 200px;
top: 5em;
left: 1em;
width: 13em;
position:absolute;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:90%;
}
#navigation ul {
list-style: none;
margin: 0;
padding: 0;
}
#navigation li {
border-bottom: 1px solid #ED9F9F;
}
#navigation li a {
display: block;
padding: 5px 5px 5px 0.5em;
border-left: 12px solid #711515;
border-right: 1px solid #711515;
background-color: #B51032;
color: #FFFFFF;
text-decoration: none;
}
#navigation li a:hover {
background-color: #711515;
color: #FFFFFF;
}
#navigation ul ul {
margin-left: 12px;
}
#navigation ul ul li {
border-bottom: 1px solid #711515;
margin:0;
background-color: #ED9F9F;
color: #711515;
}
#navigation ul ul a:link, #navigation ul ul a:visited {
background-color: #ED9F9F;
color: #711515;
}
#navigation ul ul a:hover {
background-color: #711515;
color: #FFFFFF;
}
显示结果是这样的:
5. 添加breadcrumb导航
breadcrumb导航在asp.net 2.0中是简单的-只要添加一个SiteMapPath控件到页面上就可以了;不需要更多的代码。
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://yuyijq.cnblogs.com/Images/OutliningIndicators/None.gif)
6. ViewState 当你点击返回上一级时,你在上一个页面填写的内容会不会还在。
最终生成HTML时ViewState被系列化并保存在一个隐藏的表单域中。控件用ViewState来记忆它们在页面返回时被程序改变的状态,比如Web控件绑定的数据。如果视图状态允许信息可以在页面返回时保持,它会增大发送到客户端HTML代码的尺寸。
可以将EnableViewState属性设为false在页面级或者控件级关闭视图状态。
7. Web User Control
出处:http://www.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。