All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Visual,Studio,2008,Service,Pack,1,-,BETA,发布_[Asp.Net教程]
asp.net2.0中Cookie对象的应用实例
ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)_[Asp.Net教程]
Asp.net无刷新中文验证码调试成功,特分享给大家_[Asp.Net教程]
五种ADO.NET数据库连接知识简介_[Asp.Net教程]
ASP.NET2.0中Gridview的使用技巧_[Asp.Net教程]
ASP.NET技巧:一个在移动设备中获取路径的方法_.net资料_编程技术
phpMyAdmin安装配置方法全过程_php资料_编程技术
C#中的类型相等与恒等(Equality,&,Identity)_[Asp.Net教程]
数据库的分页问题_[SQL Server教程]
Reading number is top 10 pictures
西班牙山村小景4
The money of more than 100 countries and regions19
Discharge accidentally Actresses by the breast3
穷哥们向美女求婚攻略
日本小萝莉2
南昌铁路局攸县车站125户铁路职工微利房终成骗局
玩手机对身体不好
到底是谁撞谁呀?
到南昌西站了1
人美胸美腿更美3
Download software ranking
Dance with duck(male prostitution)
WebService在.NET中的实战应用教学视频 → 第1集
XML+Web+Service开发教程
matrix2
Tram sex maniac 2 (H) rar bag12
终极变速大师Speeder3.26
C#与.NET技术平台实战演练
Ashlynn Video3
Wild things 2
都市狐狸姑娘传
delv published in(发表于) 2014/1/6 8:48:02 Edit(编辑)
ASP.NET,2.0中动态修改页面标题_[Asp.Net教程]

ASP.NET,2.0中动态修改页面标题_[Asp.Net教程]

ASP.NET 2.0中动态修改页面标题_[Asp.Net教程]























在老外的站上看到解决的好方法,故简单编译之:
在一个asp.net 的应用中,经常要动态修改页面的标题,一个典型的例子就是,在一个页面导航的控件中,希望用户点选哪一个连接,在页面的title里就显示相关的内容,举个例子,比如一个网站,有如下的网站架构:
有图书分类,下面再有中国图书,外国图书分类,则一般可以用树形或者asp.net 2.0的新增加的导航栏控件
(sitemap),来实现,比如




图书--->中国图书;
图书---->外国图书
等,而如果这个时候,能在页面的部分,也能显示比如"图书-->中国图书"这样,那就更加直观明显了,<BR>在asp.net 2.0中,我们可以使用<head>部分的服务端控件来实现了,首先,要添加标记<BR><head runat="server"></P> <br/> <br/> <br/><P>然后可以在page_load事件中,以如下形式改边其title的内容了,如<BR>Page.Header.Title = "The current time is: " & DateTime.Now.ToString() <BR>,也可以简单写成page.title.</P> <br/> <br/> <br/><P>然后,我们可以通过这样的办法,将其于sitemap控件结合了,实现方法如下:</P> <br/> <br/> <br/><P>Const DEFAULT_UNNAMED_PAGE_TITLE As String = "Untitled Page"<BR> Const DEFAULT_PAGE_TITLE As String = "Welcome to my Website!!"</P> <br/> <br/> <br/><P> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<BR> 'Set the page's title, if needed<BR> If String.IsNullOrEmpty(Page.Title) OrElse Page.Title = DEFAULT_UNNAMED_PAGE_TITLE Then<BR> If SiteMap.CurrentNode Is Nothing Then<BR> Page.Title = DEFAULT_PAGE_TITLE<BR> Else<BR> Page.Title = GetPageTitleBasedOnSiteNavigation()</P> <br/> <br/> <br/><P> 'Can also use the following if you'd rather<BR> 'Page.Title = GetPageTitleBasedOnSiteNavigationUsingRecursion(SiteMap.CurrentNode)<BR> End If<BR> End If<BR> End Sub</P> <br/> <br/> <br/><P> Private Function GetPageTitleBasedOnSiteNavigation() As String<BR> If SiteMap.CurrentNode Is Nothing Then<BR> Throw New ArgumentException("currentNode cannot be Nothing")<BR> End If</P> <br/> <br/> <br/><P> 'We are visiting a page defined in the site map - build up the page title<BR> 'based on the site map node's place in the hierarchy</P> <br/> <br/> <br/><P> Dim output As String = String.Empty<BR> Dim currentNode As SiteMapNode = SiteMap.CurrentNode</P> <br/> <br/> <br/><P> While currentNode IsNot Nothing<BR> If output.Length > 0 Then<BR> output = currentNode.Title & " :: " & output<BR> Else<BR> output = currentNode.Title<BR> End If</P> <br/> <br/> <br/><P> currentNode = currentNode.ParentNode<BR> End While</P> <br/> <br/> <br/><P> Return output<BR> End Function</P> <br/> <br/> <br/><P>  在上面的代码中,首先预定义了两个常量,然后逐步建立sitemap的结点,一开始结点是null的,然后再调用GetPageTitleBasedOnSiteNavigation() 这个过程,在每建立一个sitemap的结点时,用字符串进行连接,最后返回给page.title即可实现,当然也可以用递归实现.</P> <br/> <br/> <br/> <br/> <br/>来源:<FONT color=#ff0000>博客园</FONT> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> </div> </td> </tr> <tr> <td colspan='3' style='width:800px; height:auto;'> <iframe id='iframepage' name='iframepage' src='../../ForJavaScript1.aspx?newsId=8653&pageIndex=1' scrolling=no frameborder='0' width='100%' onLoad='iFrameHeight()' > </iframe> </td> </tr> </table> </center> </div> </td> <td style='width:200px; height:auto; vertical-align:top;'> <div> <table> <tr> <td style='width:200px; height:auto;'> <div><script language="JavaScript" src="../../js/guanggaointexthtmlright1.js" type="text/javascript"></script></div> </td> </tr> <tr> <td style='width:200px; height:auto;'> <div><script language="JavaScript" src="../../js/guanggaointexthtmlright2.js" type="text/javascript"></script></div> </td> </tr> </table> </div> </td> </tr> </table> <hr style="width:1200px; height:1px;" /> <table> <tr> <td align="left"> <div><script language="JavaScript" src="../../js/guanggaoinhtmlend.js" type="text/javascript"></script></div> </td> </tr> <tr> <td align="left"> <div><script language="JavaScript" src="../../js/guanggaoinhtmlend2.js" type="text/javascript"></script></div> </td> </tr> </table> </center> </div> </form> </center> <hr style="width:1200px; height:1px;" /> <center> <a href="http://del.icio.us/post" onclick="window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=700,height=400'); return false;"><img alt="添加到del.icio.us" src='../ico_share/ico_delicious.gif' border="0" /></a> <a href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange ().text:''):(d.getSelection?d.getSelection():'');void(vivi=window.open('http://vivi.sina.com.cn/collect/icollect.php?pid=2008&title='+escape(d.title)+'&url='+escape(d.location.href)+'&desc='+escape(t),'vivi','scrollbars=no,width=480,height=480,left=75,top=20,status=no,resizable=yes'));vivi.focus();" title="收藏的网页将被永久地保存到爱问ViVi收藏夹http://vivi.sina.com.cn"><img alt="添加到新浪ViVi" src='../ico_share/ico_vivi.gif' border="0" /></a> <a href="javascript:window.open('http://cang.baidu.com/do/add?it='+encodeURIComponent(document.title.substring(0,76))+'&iu='+encodeURIComponent(location.href)+'&fr=ien#nw=1','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0" style="color:#000000;text-decoration:none;font-size:12px;font-weight:normal"><img alt="添加到百度搜藏" src='../ico_share/ico_baidu.gif' border="0" /></a> <a href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange ().text:''):(d.getSelection?d.getSelection():'');void(vivi=window.open('http://my.poco.cn/fav/storeIt.php?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'_blank','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));" title="收藏到POCO网摘http://share.poco.cn"><img alt="添加到POCO网摘" src='../ico_share/ico_poco.gif' border="0" /></a> <a href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();" title="功能强大的网络收藏夹,一秒钟操作就可以轻松实现保存带来的价值、分享带来的快乐"><img alt="添加到天天网摘365Key" src='../ico_share/ico_365key.gif' border="0" /></a> <a href="javascript:t=document.title;u=location.href;e=document.selection?(document.selection.type!='None'?document.selection.createRange().text:''):(document.getSelection?document.getSelection():'');void(open('http://bookmark.hexun.com/post.aspx?title='+escape(t)+'&url='+escape(u)+'&excerpt='+escape(e),'HexunBookmark','scrollbars=no,width=600,height=450,left=80,top=80,status=no,resizable=yes'));"><img alt="添加到和讯网摘" src='../ico_share/ico_hexun.gif' border="0" /></a> <a href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(yesky=window.open('http://hot.yesky.com/dp.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t)+'&st=2','_blank','scrollbars=no,width=400,height=480,left=75,top=20,status=no,resizable=yes'));yesky.focus();"title="推荐到天极网摘 http://hot.my.yesky.com [鼠标划选本文摘要,然后点击本图片]"><img alt="添加到天极网摘" src='../ico_share/ico_yesky.gif' border="0" /></a> <a href="javascript:desc='';via='';if(document.referrer)via=document.referrer;if(typeof(_ref)!='undefined')via=_ref;if(window.getSelection)desc=window.getSelection();if(document.getSelection)desc=document.getSelection();if(document.selection)desc=document.selection.createRange().text;void(open('http://www.hemidemi.com/user_bookmark/new?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&description='+encodeURIComponent(desc)+'&via='+encodeURIComponent(via)));"><img alt="添加到黑米书签" src='../ico_share/ico_hemidemi.gif' border="0" /></a> <a href="javascript:window.open('http://shuqian.qq.com/post?from=3&title='+encodeURIComponent(document.title)+'&uri='+encodeURIComponent(document.location.href)+'&jumpback=2&noui=1','favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');void(0)"><img alt="添加到QQ书签" src='../ico_share/ico_qq.gif' border="0" /></a> <a href="#" onclick="window.open('http://myweb.cn.yahoo.com/popadd.html?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title), 'Yahoo','scrollbars=yes,width=780,height=550,left=80,top=80,status=yes,resizable=yes');"><img alt="添加到雅虎收藏" src='../ico_share/ico_yahoo.gif' border="0" /></a> <a title="推荐到diglog" href="javascript://" onclick="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.diglog.com/submit.aspx?title='+escape(d.title)+'&url='+escape(d.location.href)+'&description='+escape(t),'keyit','resizable,location,menubar,toolbar,scrollbars,status'));keyit.focus();"><img alt="添加到奇客发现" src='../ico_share/ico_diglog.gif' border="0" /></a> <a href="#" onclick="var s=document.createElement('script');s.type='text/javascript';s.src='http://www.diigo.com/javascripts/webtoolbar/diigolet_b_h_b.js';document.body.appendChild(s);"><img alt="diigo it" src='../ico_share/ico_diigo.gif' border="0" /></a> <a href="javascript:var d=document,w=window,f='http://fanfou.com/share',l=d.location,e=encodeURIComponent,p='?u='+e(l.href)+'?t='+e(d.title)+'?d='+e(w.getSelection?w.getSelection().toString():d.getSelection?d.getSelection():d.selection.createRange().text)+'?s=bl';if(!w.open(f+'r'+p,'sharer','toolbar=0,status=0,width=600,height=400')){l.href=f+'.new'+p;}void(0)"><img alt="添加到饭否" src='../ico_share/ico_fanfou.gif' border="0" /></a> <a target=_blank href="http://www.feedou.com/addchannelservlet?commandkey=takersslog&url=http://digimarketing.cn/modules/article/xml.php?rss"><img alt="添加到飞豆订阅" src='../ico_share/ico_feedou.gif' border="0" /></a> <a target=_blank href="http://www.zhuaxia.com/add_channel.php?sourceid=102&url=http%3A%2F%2Fdigimarketing.cn"><img alt="添加到抓虾收藏" src='../ico_share/ico_zhuaxia.gif' border="0" /></a> <a target="_blank" href="http://www.xianguo.com/subscribe.php?url=digimarketing.cn"><img alt="添加到鲜果订阅" src='../ico_share/ico_xianguo.gif' border="0" /></a> <a href="javascript:;" onclick="window.open('http://digg.com/submit?phase=2&url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title)); return false;"><img alt="digg it" src='../ico_share/ico_digg.gif' border="0" /></a> <a target=_blank href="http://funp.com/push/submit/add.php?&via=tools" title="貼到funP"><img alt="貼到funP" src='../ico_share/ico_funp.gif' border="0" /></a> <a target="_blank" href="http://reader.yodao.com/b.do?url=digimarketing.cn"><img alt="添加到有道阅读" src='../ico_share/ico_yodao.gif' border="0" /></a> <a href="javascript:;" onclick="window.open('http://favorites.live.com/quickadd.aspx?url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title)); return false;"><img alt="Live Favorites" src='../ico_share/ico_windows.gif' border="0" /></a> <a href="javascript:;" onclick="window.open('http://www.newsvine.com/_tools/seed&save?popoff=0&u=' + encodeURIComponent(location.href) + '&h=' + encodeURIComponent(document.title)); return false;"><img alt="添加到Newsvine" src='../ico_share/ico_newsvine.gif' border="0" /></a> <a onclick="javascript:window.print();" href="javascript:;"><img src="../ico_share/ico_print.gif" alt="打印本页" border="0" /></a> <a onclick='javascript:window.location="mailto:?subject=[ Enter your own subject line ]& body=" + "Check out this link: " + window.location;' href="javascript:;"><img alt="用Email发送本页" src='../ico_share/ico_mail.gif' border="0" /></a> <script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436,scrollbars=1, resizable=1');return false;}</script> <a href="http://www.facebook.com/share.php?u=<url>" onclick="return fbs_click()" target="_blank" class="fb_share_link"><img alt="在Facebook上分享" src='../ico_share/ico_fb.jpg' border="0" /></a> </center> <hr style="width:1200px; height:1px;" /> <center > <!--网站底部--> <div style=" width:1200px; height:100px; background-color:#FFFFFF;"> <hr style=" width:1200px; height:1px;"/> <table> <tr style=" height:50px; width:1200px;"> <td align="center" style="height:50px;"> <a href="../../disclaimer.html" style="font-family:黑体; font-size:small; color:#555;" target="_blank">Disclaimer</a> </td> <td align="center" style="height:50px;"> <a href="../../privacy policy.html" style="font-family:黑体; font-size:small; color:#555;" target="_blank">Privacy Policy</a> </td> <td align="center" style="height:50px;"> <a href="../../AboutUs.html" style="font-family:黑体; font-size:small; color:#555;" target="_blank">About us</a> </td> <td align="center" style="height:50px;"> <a href="../../SiteMap.html" style="font-family:黑体; font-size:small; color:#555;" target="_blank">Site Map</a> </td> <td align="center" style="height:50px;"> <!--百度网站统计--> <script type="text/javascript"> var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fcd1d276abd98aad311a7e9ab1f772b56' type='text/javascript'%3E%3C/script%3E")); </script> </td> <td align="center" style="height:50px;"> </td> <td align="center" style="height:50px;"> <a href="http://webscan.360.cn"><img border="0" src="http://webscan.360.cn/status/pai/hash/494b6dad04e216e4d1f270ad7bfe37f4"/></a> </td> </tr> </table> <hr style=" width:1200px; height:1px;"/> If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长) <hr style=" width:1200px; height:1px;"/> <table> <tr> <td><img src="../../images/mmqrcode1435163607101.png" alt=""/></td> <td></td> <td><img src="../../images/mmqrcode1435163324094.png" alt=""/></td> </tr> <tr> <td align="right"> Copyright ©2011-</td> <td align="left"><div id="yearTime"></div> </td> <td align="left"> uuhomepage.com, Inc. All rights reserved. </td> <td> <div><script language="JavaScript" src="../../js/guanggao6.js" type="text/javascript"></script></div> </td> </tr> </table> </div> </center> </body> </html>