asp.net 中的 Page.Title 与 Title 标签 [英] Page.Title vs Title tag in asp.net

查看:21
本文介绍了asp.net 中的 Page.Title 与 Title 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 asp.net.我注意到我们可以通过两种方式配置页面标题(静态和动态):

I am using asp.net. I have noticed that we can configure page title (static and dynamic both) in two ways:

  1. 我们在页面指令中有一个 Title 属性:

  <%@ Page Language="C#" Inherits="_Default"  Title="My Title" ......%>

  • 我们在页面中也有 </code> 标签:</p> <pre><code><code><title runat="server" id="MyTitle"> My Title</title> </code></code></pre> <p class="cn"></li></p> <p class="cn">两者都可以在代码隐藏文件中访问:<em class="showen"></em></p> <p class="en">Both can be accessed in code-behind file:</p> <pre><code><code> MyTitle.Text = "Title from Code behind"; Page.Title = "Page Title from CS"; </code></code></pre> <p class="cn">而且我发现页面指令覆盖了 html 标题.那么我们应该使用哪一个,为什么?<em class="showen"></em></p> <p class="en">And i have found the page directive overrides the html title. So Which one should we use and why ?</p> <h3 class="best_ans mt-1">推荐答案</h3> <p class="cn">最大的不同在于 <code>MyTitle.Text</code> 你必须用 <code>id</code> AND 修饰 Title 元素<code>runat</code> 属性,并记住它的名称以便您可以引用它.例如,当您使用 Masterpage 时,从子页面访问此值也不是那么容易..<em class="showen"></em></p> <p class="en">The biggest difference is that with <code>MyTitle.Text</code> you have to decorate Title element with an <code>id</code> AND <code>runat</code> attributes, and remember it's name so you can reference it. Also accessing this value isn't that easy from child pages when you're using Masterpage for instance..</p> <p class="cn">另一方面,<code>Page.Title</code> 对每个页面都是通用的,所以在我看来它更通用.与您合作的每位新开发人员都无需学习任何新知识,只需使用 Page.Title 格式即可..<em class="showen"></em></p> <p class="en">On the other hand, <code>Page.Title</code> is common to every Page, so it's more universal in my opinion. Every new developer you'll work with won't have to learn anything new, just use the Page.Title format..</p> <p class="cn">所以我的投票会投给传统的"<code>Page.Title</code><em class="showen"></em></p> <p class="en">So my vote would go to the "traditional" <code>Page.Title</code></p> <p class="cn">无论您喜欢使用哪种方式,请坚持使用,这样您就不会混合各种设置标题的方法.这样您就不必担心哪个事件先发生或您的同事会覆盖您的价值观.<em class="showen"></em></p> <p class="en">Whichever you like to use, stick with it, so you won't mix various ways of setting the title. That way you won't have to worry about which event happens first or about your colleague overwriting your values.</p> <p>这篇关于asp.net 中的 Page.Title 与 Title 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!</p> </div> <div class="arc-body-main-more"> <span onclick="unlockarc('2775664');">查看全文</span> </div> </div> <div> </div> <div class="wwads-cn wwads-horizontal" data-id="166" style="max-width:100%;border: 4px solid #666;"></div> </div> </article> <div id="arc-ad-2" class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="widget bgwhite radius-1 mb-1 shadow widget-rel"> <h5>相关文章</h5> <ul> <li> <a target="_blank" title="asp.net中的Page.Title vs Title标签" href="/2186343.html"> asp.net中的Page.Title vs Title标签; </a> </li> <li> <a target="_blank" title="ASP.NET MVC 3中的ViewBag.Title与Page.Title" href="/1947198.html"> ASP.NET MVC 3中的ViewBag.Title与Page.Title; </a> </li> <li> <a target="_blank" title="如何使用eval在codebehind设置Page.Title" href="/264716.html"> 如何使用eval在codebehind设置Page.Title; </a> </li> <li> <a target="_blank" title="如何在codebehind中使用Eval来设置Page.Title" href="/603709.html"> 如何在codebehind中使用Eval来设置Page.Title; </a> </li> <li> <a target="_blank" title="How to crawl the title of the page?" href="/2918440.html"> How to crawl the title of the page?; </a> </li> <li> <a target="_blank" title="ASP.NET中的PreviousPage.Title存在问题" href="/1201576.html"> ASP.NET中的PreviousPage.Title存在问题; </a> </li> <li> <a target="_blank" title="Python selenium get page title" href="/2965612.html"> Python selenium get page title; </a> </li> <li> <a target="_blank" title="渲染span标记与ASP.NET MVC 3帮手title属性" href="/278447.html"> 渲染span标记与ASP.NET MVC 3帮手title属性; </a> </li> <li> <a target="_blank" title="UITabBarItem.title与UINavigationController.title" href="/2141247.html"> UITabBarItem.title与UINavigationController.title; </a> </li> <li> <a target="_blank" title="替代ViewBag.Title在ASP.NET MVC 3" href="/287511.html"> 替代ViewBag.Title在ASP.NET MVC 3; </a> </li> <li> <a target="_blank" title="Including the title page and back page in a quarto book in PDF format" href="/2966537.html"> Including the title page and back page in a quarto book in PDF format; </a> </li> <li> <a target="_blank" title="javascript - html中的a标签的title问题" href="/713984.html"> javascript - html中的a标签的title问题; </a> </li> <li> <a target="_blank" title="AddPrivateFont to App Title / Title bar in WxPython?" href="/2955686.html"> AddPrivateFont to App Title / Title bar in WxPython?; </a> </li> <li> <a target="_blank" title="wp_title过滤器对&lt; title&gt;无效.标签" href="/1744861.html"> wp_title过滤器对&lt; title&gt;无效.标签; </a> </li> <li> <a target="_blank" title="WordPress 中的 get_page_by_title.如何使用获取帖子?" href="/2432143.html"> WordPress 中的 get_page_by_title.如何使用获取帖子?; </a> </li> <li> <a target="_blank" title="i标签的Alt或title属性" href="/2088100.html"> i标签的Alt或title属性; </a> </li> <li> <a target="_blank" title="Page&lt; title&gt;来自include变量?" href="/1051647.html"> Page&lt; title&gt;来自include变量?; </a> </li> <li> <a target="_blank" title="How to include page title of wordpress post in the content possibly with a shortcode" href="/2906152.html"> How to include page title of wordpress post in the content possibly with a shortcode; </a> </li> <li> <a target="_blank" title="Why am I seeing the &#39;title&#39; in Web-page&#39;s body (Not only in Title Bar)?" href="/2962744.html"> Why am I seeing the &#39;title&#39; in Web-page&#39;s body (Not only in Title Bar)?; </a> </li> <li> <a target="_blank" title="ASP.NET MVC 3模型绑定 - ViewBag.Title冲突与ID输入=&QUOT;标题&QUOT;" href="/288400.html"> ASP.NET MVC 3模型绑定 - ViewBag.Title冲突与ID输入=&QUOT;标题&QUOT;; </a> </li> <li> <a target="_blank" title="如何在锚标签的title属性中添加图片标签?" href="/864337.html"> 如何在锚标签的title属性中添加图片标签?; </a> </li> <li> <a target="_blank" title="UI 路由器动态 <title>标签" href="/2532600.html"> UI 路由器动态 <title>标签; </a> </li> <li> <a target="_blank" title="换出&lt; title&gt; t1&lt; / title&gt;&lt; title&gt; t2&lt; / title&gt; &lt; title&gt;新标题&lt; / title&gt;&lt; title&gt;新标题&lt; / title&gt;" href="/1256706.html"> 换出&lt; title&gt; t1&lt; / title&gt;&lt; title&gt; t2&lt; / title&gt; &lt; title&gt;新标题&lt; / title&gt;&lt; title&gt;新标题&lt; / title&gt;; </a> </li> <li> <a target="_blank" title="PDO数据库访问WHERE title = $ title" href="/1665277.html"> PDO数据库访问WHERE title = $ title; </a> </li> <li> <a target="_blank" title="SwiftUI – How to set the title of a NavigationView to large title (or small)?" href="/2935852.html"> SwiftUI – How to set the title of a NavigationView to large title (or small)?; </a> </li> </ul> </div> <div class="mb-1"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834" crossorigin="anonymous"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5038752844014834" data-ad-slot="3921941283"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="side"> <div class="widget widget-side bgwhite mb-1 shadow"> <h5>C#/.NET最新文章</h5> <ul> <li> <a target="_blank" title="smtp.live.com - 邮箱不可用。服务器响应为:5.7.3请求的操作中止;用户未通过身份验证" href="/444094.html"> smtp.live.com - 邮箱不可用。服务器响应为:5.7.3请求的操作中止;用户未通过身份验证; </a> </li> <li> <a target="_blank" title="C#WinForms应用程序失败在发送电子邮件:远程名称无法解析:'smtp.gmail.com;操作超时" href="/32030.html"> C#WinForms应用程序失败在发送电子邮件:远程名称无法解析:'smtp.gmail.com;操作超时; </a> </li> <li> <a target="_blank" title="Windows应用程序已停止工作::事件名称CLR20r3" href="/7498.html"> Windows应用程序已停止工作::事件名称CLR20r3; </a> </li> <li> <a target="_blank" title="如何设置的WebAPI控制器的multipart / form-data的" href="/294641.html"> 如何设置的WebAPI控制器的multipart / form-data的; </a> </li> <li> <a target="_blank" title="无法反序列化当前的JSON数组(例如[1,2,3])" href="/240450.html"> 无法反序列化当前的JSON数组(例如[1,2,3]); </a> </li> <li> <a target="_blank" title="如何设置一个HttpClient的请求Content-Type头?" href="/221353.html"> 如何设置一个HttpClient的请求Content-Type头?; </a> </li> <li> <a target="_blank" title="为什么发现“没有匹配请求URI的HTTP资源”这里?" href="/547804.html"> 为什么发现“没有匹配请求URI的HTTP资源”这里?; </a> </li> <li> <a target="_blank" title="如何设置一个重试次数在RabbitMQ的呢?" href="/10344.html"> 如何设置一个重试次数在RabbitMQ的呢?; </a> </li> <li> <a target="_blank" title="任务&LT;&GT;不包含'GetAwaiter“的定义" href="/300688.html"> 任务&LT;&GT;不包含'GetAwaiter“的定义; </a> </li> <li> <a target="_blank" title="这是不可能连接到redis的服务器(S);以创建断开连接多路复用器" href="/421232.html"> 这是不可能连接到redis的服务器(S);以创建断开连接多路复用器; </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门教程 </h5> <ul> <li> <a target="_blank" title="Java教程" href="/OnLineTutorial/java/index.html"> Java教程 </a> </li> <li> <a target="_blank" title="Apache ANT 教程" href="/OnLineTutorial/ant/index.html"> Apache ANT 教程 </a> </li> <li> <a target="_blank" title="Kali Linux教程" href="/OnLineTutorial/kali_linux/index.html"> Kali Linux教程 </a> </li> <li> <a target="_blank" title="JavaScript教程" href="/OnLineTutorial/javascript/index.html"> JavaScript教程 </a> </li> <li> <a target="_blank" title="JavaFx教程" href="/OnLineTutorial/javafx/index.html"> JavaFx教程 </a> </li> <li> <a target="_blank" title="MFC 教程" href="/OnLineTutorial/mfc/index.html"> MFC 教程 </a> </li> <li> <a target="_blank" title="Apache HTTP客户端教程" href="/OnLineTutorial/apache_httpclient/index.html"> Apache HTTP客户端教程 </a> </li> <li> <a target="_blank" title="Microsoft Visio 教程" href="/OnLineTutorial/microsoft_visio/index.html"> Microsoft Visio 教程 </a> </li> </ul> </div> <div class="widget widget-side bgwhite mb-1 shadow"> <h5> 热门工具 </h5> <ul> <li> <a target="_blank" title="Java 在线工具" href="/Onlinetools/details/4"> Java 在线工具 </a> </li> <li> <a target="_blank" title="C(GCC) 在线工具" href="/Onlinetools/details/6"> C(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="PHP 在线工具" href="/Onlinetools/details/8"> PHP 在线工具 </a> </li> <li> <a target="_blank" title="C# 在线工具" href="/Onlinetools/details/1"> C# 在线工具 </a> </li> <li> <a target="_blank" title="Python 在线工具" href="/Onlinetools/details/5"> Python 在线工具 </a> </li> <li> <a target="_blank" title="MySQL 在线工具" href="/Onlinetools/Dbdetails/33"> MySQL 在线工具 </a> </li> <li> <a target="_blank" title="VB.NET 在线工具" href="/Onlinetools/details/2"> VB.NET 在线工具 </a> </li> <li> <a target="_blank" title="Lua 在线工具" href="/Onlinetools/details/14"> Lua 在线工具 </a> </li> <li> <a target="_blank" title="Oracle 在线工具" href="/Onlinetools/Dbdetails/35"> Oracle 在线工具 </a> </li> <li> <a target="_blank" title="C++(GCC) 在线工具" href="/Onlinetools/details/7"> C++(GCC) 在线工具 </a> </li> <li> <a target="_blank" title="Go 在线工具" href="/Onlinetools/details/20"> Go 在线工具 </a> </li> <li> <a target="_blank" title="Fortran 在线工具" href="/Onlinetools/details/45"> Fortran 在线工具 </a> </li> </ul> </div> </div> </div> <script type="text/javascript">var eskeys = 'asp.net,中,的,page.title,与,title,标签'; var cat = 'cc';';//c</script> </div> <div id="pop" onclick="pophide();"> <div id="pop_body" onclick="event.stopPropagation();"> <h6 class="flex flex101"> 登录 <span onclick="pophide();">关闭</span> </h6> <div class="pd-1"> <div class="wxtip center"> <span>扫码关注<em>1秒</em>登录</span> </div> <div class="center"> <img id="qr" src="https://huajiakeji.com/Content/Images/qrydx.jpg" alt="" style="width:150px;height:150px;" /> </div> <div style="margin-top:10px;display:flex;justify-content: center;"> <input type="text" placeholder="输入验证码" id="txtcode" autocomplete="off" /> <input id="btngo" type="button" onclick="chk()" value="GO" /> </div> <div class="center" style="margin: 4px; font-size: .8rem; color: #f60;"> 发送“验证码”获取 <em style="padding: 0 .5rem;">|</em> <span style="color: #01a05c;">15天全站免登陆</span> </div> <div id="chkinfo" class="tip"></div> </div> </div> </div> <script type="text/javascript" src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/highlight.min.js"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/base.js?v=0.22"></script> <script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/tui.js?v=0.11"></script> <footer class="footer"> <div class="container"> <div class="flink mb-1"> 友情链接: <a href="https://www.it1352.com/" target="_blank">IT屋</a> <a href="https://huajiakeji.com/" target="_blank">Chrome插件</a> <a href="https://www.cnplugins.com/" target="_blank">谷歌浏览器插件</a> </div> <section class="copyright-section"> <a href="https://www.it1352.com" title="IT屋-程序员软件开发技术分享社区">IT屋</a> ©2016-2022 <a href="http://www.beian.miit.gov.cn/" target="_blank">琼ICP备2021000895号-1</a> <a href="/sitemap.html" target="_blank" title="站点地图">站点地图</a> <a href="/Home/Tags" target="_blank" title="站点标签">站点标签</a> <a target="_blank" alt="sitemap" href="/sitemap.xml">SiteMap</a> <a href="/1155981.html" title="IT屋-免责申明"><免责申明></a> 本站内容来源互联网,如果侵犯您的权益请联系我们删除. </section> <!--统计代码--> <script type="text/javascript"> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?0c3a090f7b3c4ad458ac1296cb5cc779"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script type="text/javascript"> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </div> </footer> </body> </html>