asp.net 2.0中动态修改页面标题
来源:互联网 发布:mac可以用office吗 编辑:程序博客网 时间:2024/05/20 15:11
在一个
有图书分类,下面再有中国图书,外国图书分类,则一般可以用树形或者asp.net 2.0的新增加的导航栏控件
(sitemap),来实现,比如
图书--->中国图书;
图书---->外国图书
等,而如果这个时候,能在页面的<title>部分,也能显示比如"图书-->中国图书"这样,那就更加直观明显了,
在asp.net 2.0中,
<head runat="server">
然后可以在page_load事件中,以如下形式改边其title的内容了,如
Page.Header.Title = "The current time is: " & DateTime.Now.ToString()
,也可以简单写成page.title.
然后,我们可以通过这样的办法,将其于sitemap控件结合了,实现方法如下:
Const DEFAULT_UNNAMED_PAGE_TITLE As String = "Untitled Page"
Const DEFAULT_PAGE_TITLE As String = "Welcome to my Website!!"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set the page's title, if needed
If String.IsNullOrEmpty(Page.Title) OrElse Page.Title = DEFAULT_UNNAMED_PAGE_TITLE Then
If SiteMap.CurrentNode Is Nothing Then
Page.Title = DEFAULT_PAGE_TITLE
Else
Page.Title = GetPageTitleBasedOnSiteNavigation()
'Can also use the following if you'd rather
'Page.Title = GetPageTitleBasedOnSiteNavigationUsingRecursion(SiteMap.CurrentNode)
End If
End If
End Sub
Private Function GetPageTitleBasedOnSiteNavigation() As String
If SiteMap.CurrentNode Is Nothing Then
Throw New ArgumentException("currentNode cannot be Nothing")
End If
'We are visiting a page defined in the site map - build up the page title
'based on the site map node's place in the hierarchy
Dim output As String = String.Empty
Dim currentNode As SiteMapNode = SiteMap.CurrentNode
While currentNode IsNot Nothing
If output.Length > 0 Then
output = currentNode.Title & " :: " & output
Else
output = currentNode.Title
End If
currentNode = currentNode.ParentNode
End While
Return output
End Function
在上面的
GetPageTitleBasedOnSiteNavigation() 这个过程,在每建立一个sitemap的结点时,用字符串进行连接,最后返回给page.title即可实现,当然也可以用递归实现
- asp.net 2.0中动态修改页面标题
- asp.net 2.0中动态修改页面标题
- asp.net 2.0中动态修改页面标题
- asp.net 2.0中动态修改页面标题
- asp.net 2.0中动态修改页面标题
- c#2.0中动态修改页面标题
- c#2.0中动态修改页面标题
- asp.net2.0中动态修改页面标题
- 在ASP.net中动态修改Web的标题
- 动态改变Asp.net页面标题
- ASP.NET实现动态页面标题
- 动态改变Asp.net页面标题
- asp.net页面中标题单点解决方案
- 动态改变Asp.net页面标题方法整合
- 动态改变Asp.net页面标题方法整合
- js动态修改页面标题
- asp.net1.1中动态更改页面标题
- asp.net1.1中动态更改页面标题
- ActiveReport for .net 3.0 最新版本的破解版本,强烈推荐!
- INF文件格式小结
- net发送邮件集
- 明年1月1日起房奴将一次性消化5次加息所增负担
- Visual C#网络编程之TCP(转载)
- asp.net 2.0中动态修改页面标题
- [转]mysql 5.0存储过程
- ASP.NET操作IIS中的虚拟目录
- 限制鼠标位置 和拖动标签
- J2ME程序优化
- Access 通用数据访问类(asp.net 2.0 c#)
- Web发布cab文件打包的ActiveX控件总结
- c# 关闭messageBox
- Hibernate annotations one2one with WithExplicitFk 单向一对一 有外键