2013-07-16 64 views
1

我有幾個頁面的網站,我想在頁面的標題是:創建子標題與母版頁的ContentPlaceHolder

Foo - 1st Page 
Foo - 2nd Page 
Foo - 3rd Page 

我已經創建了一個母版頁用下面的代碼:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Foo.master.cs" Inherits="Foo" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>Foo - <asp:ContentPlaceHolder ID="SubTitle" runat="server"></asp:ContentPlaceHolder></title> 
</head> 
<body> 
    <asp:ContentPlaceHolder ID="MainContent" runat="server"> 
    </asp:ContentPlaceHolder> 
</body> 
</html> 

,然後將每個頁面看起來是這樣的:

<%@ Page Language="C#" MasterPageFile="~/Foo.Master" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="SubTitle" runat="server">1st Page</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <a href="Page2.aspx">Page 2</a> 
</asp:Content> 

當我加載我期望瀏覽器的頁面標題爲Foo - 1st Page,但它只是1st Page

HTML源代碼是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><title> 
    1st Page 
</title></head> 
<body> 

<a href="Page2.aspx">Page 2</a> 

</body> 
</html> 

我在做什麼錯?

+0

什麼是你看到的產生標籤? (對我來說,無論如何,這是佔位符的一個不尋常的用法。)我在想,如果更好的解決方案可能是在代碼隱藏中設置Page的Title屬性。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/282194/">ThatBlairGuy</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">@ThatBlairGuy - 我將html源添加到了我的問題中。 Visual Studio的主頁面模板在MasterPage的標題標籤中有一個名爲'title'的ContentPlaceHolder。我在它之前添加了「Foo - 」文本,並將其重命名爲「SubTitle」。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">回答</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">2<i class="fa fa-thumbs-up"></i></span> <i class="fa fa-check fa-2x"></i> </div> <div class="post-offset"> <div class="answer fmt"> <p>您不想從<code class="prettyprint-override">head</code>刪除<code class="prettyprint-override">runat="server"</code>;它會產生其他問題。</p> <p>使用下面的方法,它是在Visual Studio中的ASP.Net Web窗體應用程序默認的方法2012</p> <pre><code class="prettyprint-override"><!-- Master Page --> <head runat="server"> <title>Foo - <%: Page.Title %></title> </head> <!-- Content Page/xxx.aspx --> <%@ Page Title="Home Page" ...> </code></pre> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/17683750">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2013-07-16 17:57:49</span> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/296861/">Win</a></span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">非常好。謝謝。爲了我的目的,缺少'runat ='server''不會引起問題(這只是一小組測試頁面,'head'中沒有其他東西),但我已經採納了你的建議,因爲它使得代碼簡單。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">0<i class="fa fa-thumbs-up"></i></span> </div> <div class="post-offset"> <div class="answer fmt"> <p>原來,這個問題已經被問:<a href="https://stackoverflow.com/questions/3571618/asp-net-having-common-page-title-in-master-page-with-each-page-adding-page-spec">ASP.NET: Having common Page title in master page with each page adding page-specific title?</a></p> <p>閱讀的答案有後,我發現,從母版頁的<code class="prettyprint-override">head</code>元素去除<code class="prettyprint-override">runat="server"</code>的伎倆。</p> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/17683269">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2013-07-16 17:30:26</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> </div> </article> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">相關問題</div> <ul class="relative_list"> <li> 1. <a href="http://hk.uwenku.com/question/p-dpyzhhwf-ht.html" target="_blank" title="母版頁管理的ContentPlaceHolder"> 母版頁管理的ContentPlaceHolder </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-dufybvja-zv.html" target="_blank" title="母版頁標題"> 母版頁標題 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-moqjrgiw-bmg.html" target="_blank" title="母版頁標題導航"> 母版頁標題導航 </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-dhdbpscw-bcx.html" target="_blank" title="如何創建母版頁?"> 如何創建母版頁? </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-aydnavtw-zx.html" target="_blank" title="母版頁可以引用具有相同內容和contentplaceholder標籤的另一個母版頁嗎?"> 母版頁可以引用具有相同內容和contentplaceholder標籤的另一個母版頁嗎? </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-yjhyxzox-dy.html" target="_blank" title="如何訪問屬性從頁面的ContentPlaceHolder在我的母版"> 如何訪問屬性從頁面的ContentPlaceHolder在我的母版 </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-uxhaaulj-nr.html" target="_blank" title="母版頁標題中的Javascript"> 母版頁標題中的Javascript </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-mloeaicf-bnk.html" target="_blank" title="從父母母版頁的子母版頁訪問元素"> 從父母母版頁的子母版頁訪問元素 </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-gwigajin-bky.html" target="_blank" title="PostbackUrl與母版頁"> PostbackUrl與母版頁 </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-qubbiash-bac.html" target="_blank" title="jQueryUI與母版頁"> jQueryUI與母版頁 </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://hk.uwenku.com/question/p-psvevnhn-bmw.html" target="_blank" title="母版頁繼承標記問題"> 母版頁繼承標記問題 </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-eidiblza-bey.html" target="_blank" title="是否JavaScript的創建問題,當我們實現母版頁"> 是否JavaScript的創建問題,當我們實現母版頁 </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-pmebwxir-bdh.html" target="_blank" title="如何從母版頁操作ContentPlaceHolder內容"> 如何從母版頁操作ContentPlaceHolder內容 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-ayazsudo-ba.html" target="_blank" title="停止使用ContentPlaceHolder滾動到母版頁頂部?"> 停止使用ContentPlaceHolder滾動到母版頁頂部? </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-aphezbor-cr.html" target="_blank" title="如何在Joomla中創建母版頁?"> 如何在Joomla中創建母版頁? </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-zxcbrfrj-boe.html" target="_blank" title="如何使用HTML創建母版頁?"> 如何使用HTML創建母版頁? </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-hjfftaoh-ba.html" target="_blank" title="POST方法問題與母版頁"> POST方法問題與母版頁 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-zsinfwep-bea.html" target="_blank" title="是否可以創建一個選擇另一個母版頁的母版頁?"> 是否可以創建一個選擇另一個母版頁的母版頁? </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-bkmbxvnm-zg.html" target="_blank" title="問題與母版"> 問題與母版 </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-fxqkbpgo-bhy.html" target="_blank" title="我可以知道我的母版頁的ContentPlaceHolder中有哪些頁面?"> 我可以知道我的母版頁的ContentPlaceHolder中有哪些頁面? </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-qlddzzrw-tt.html" target="_blank" title="母版頁和子頁面的概念!"> 母版頁和子頁面的概念! </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-cdbttpqi-ne.html" target="_blank" title="從母版頁上的用戶控件獲取子頁面標題"> 從母版頁上的用戶控件獲取子頁面標題 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-hifocamk-nw.html" target="_blank" title="ASP.NET/SharePoint母版頁問題"> ASP.NET/SharePoint母版頁問題 </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-ogdekyrq-ms.html" target="_blank" title="jquery母版頁問題"> jquery母版頁問題 </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-wseopbbj-vu.html" target="_blank" title="SharePoint母版頁問題"> SharePoint母版頁問題 </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-dqxbbldk-yg.html" target="_blank" title="RESOLVEURL問題在母版頁"> RESOLVEURL問題在母版頁 </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-vllfwoof-mb.html" target="_blank" title="母版頁和jQuery問題"> 母版頁和jQuery問題 </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-ccgvawwo-zb.html" target="_blank" title="母版頁文件問題"> 母版頁文件問題 </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-ulwqixfv-hg.html" target="_blank" title="母版頁 - 設計問題"> 母版頁 - 設計問題 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-svlyocid-os.html" target="_blank" title="母版頁標籤在子頁面中的可見性"> 母版頁標籤在子頁面中的可見性 </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048261"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新問題 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-qrzpyrgr-pp.html" target="_blank" title="選擇所有沒有h標籤的鏈接"> 選擇所有沒有h標籤的鏈接 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-kopluyxm-ou.html" target="_blank" title="配置文件給我值隨意類"> 配置文件給我值隨意類 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-tunifaze-pd.html" target="_blank" title="nginx用URL重寫部分url? mark"> nginx用URL重寫部分url? mark </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-kocwvevm-nz.html" target="_blank" title="Python Web Scrape Cycle選項卡"> Python Web Scrape Cycle選項卡 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-ahggiyrx-ok.html" target="_blank" title="安全的字符串輸出陣營生態系統"> 安全的字符串輸出陣營生態系統 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-rnxnvwes-ne.html" target="_blank" title="再次按下Drawtoggle後關閉抽屜"> 再次按下Drawtoggle後關閉抽屜 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-gojblsun-nq.html" target="_blank" title="在上傳laravel之前的圖像裁剪"> 在上傳laravel之前的圖像裁剪 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-ubufhmjd-mm.html" target="_blank" title="嘗試在Roku通道中斷開連接會引發錯誤"> 嘗試在Roku通道中斷開連接會引發錯誤 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-nbcltjgs-ma.html" target="_blank" title="如何發佈到外部IP?"> 如何發佈到外部IP? </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-zjdfagbc-cy.html" target="_blank" title="生產基於優先級列表"> 生產基於優先級列表 </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 相關問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-dpyzhhwf-ht.html" target="_blank" title="母版頁管理的ContentPlaceHolder"> 母版頁管理的ContentPlaceHolder </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-dufybvja-zv.html" target="_blank" title="母版頁標題"> 母版頁標題 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-moqjrgiw-bmg.html" target="_blank" title="母版頁標題導航"> 母版頁標題導航 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-dhdbpscw-bcx.html" target="_blank" title="如何創建母版頁?"> 如何創建母版頁? </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-aydnavtw-zx.html" target="_blank" title="母版頁可以引用具有相同內容和contentplaceholder標籤的另一個母版頁嗎?"> 母版頁可以引用具有相同內容和contentplaceholder標籤的另一個母版頁嗎? </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-yjhyxzox-dy.html" target="_blank" title="如何訪問屬性從頁面的ContentPlaceHolder在我的母版"> 如何訪問屬性從頁面的ContentPlaceHolder在我的母版 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-uxhaaulj-nr.html" target="_blank" title="母版頁標題中的Javascript"> 母版頁標題中的Javascript </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-mloeaicf-bnk.html" target="_blank" title="從父母母版頁的子母版頁訪問元素"> 從父母母版頁的子母版頁訪問元素 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-gwigajin-bky.html" target="_blank" title="PostbackUrl與母版頁"> PostbackUrl與母版頁 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-qubbiash-bac.html" target="_blank" title="jQueryUI與母版頁"> jQueryUI與母版頁 </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://hk.uwenku.com/contact">聯系我們</a></li> <li>© 2020 HK.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>