Setting Page Titles 2005 Style

By Philip Miseldine

Little tip.

To set the page title on an ASP.NET Web From using Whidbey, add runat=”server” properties to the head and title tags in your HTML:

<br /> </head></code> <p>Now, you can set the page easily using:</p> <p><code><br /> this.Title = "My new page title";</code> <p>Simple as!</p> </div> <div class="l-mb3"> <thumbvoter-buttons id="38518" url="" user_rating="0" channel="Programming" /> </div> </div> <div class="Article_authorBio l-mb4 l-pa3 t-bg-white m-border"> <div class="l-d-f"> <a class="l-s5 l-mr3 l-round l-o-h" href=""> <img src="" width="96" height="96" alt="" class="avatar avatar-96 wp-user-avatar wp-user-avatar-96 photo avatar-default" /> </a> <div class="f-lh-title"> <div class="f-c-grey-300">Meet the author</div> <div class="f-large"> <a class="f-bold f-c-grey-500" href=""> Philip Miseldine </a> </div> </div> </div> <div class="f-light f-lh-copy l-mt3">Philip is a Computer Science PhD student at Liverpool John Moores University. He's still not mastered guitar tabs, never finished Mario, and needs a haircut. He discusses life at <a href=""></a>.</div> </div> <div class="ArticleContent_endcap"> </div> <ads-weighted widget='72' data='{"fallback":[{"id":"440","weight":"100","randMax":100}]}' fallback=''></ads-weighted> <div class="l-pa3 t-bg-white"> <a id="comments"></a> <div id="disqus_thread"> <div id="dsq-content"> <ul id="dsq-comments"> <li class="comment even thread-even depth-1" id="dsq-comment-28789"> <div id="dsq-comment-header-28789" class="dsq-comment-header"> <cite id="dsq-cite-28789"> <span id="dsq-author-user-28789">Cory M.</span> </cite> </div> <div id="dsq-comment-body-28789" class="dsq-comment-body"> <div id="dsq-comment-message-28789" class="dsq-comment-message"><p>Ooh, very nice.</p> </div> </div> </li><!-- #comment-## --> <li class="comment odd alt thread-odd thread-alt depth-1" id="dsq-comment-28790"> <div id="dsq-comment-header-28790" class="dsq-comment-header"> <cite id="dsq-cite-28790"> <span id="dsq-author-user-28790">andre</span> </cite> </div> <div id="dsq-comment-body-28790" class="dsq-comment-body"> <div id="dsq-comment-message-28790" class="dsq-comment-message"><p>uh, how do you do this under ASP.NET 1.1? using client-side javascript?</p> </div> </div> </li><!-- #comment-## --> <li class="comment even thread-even depth-1" id="dsq-comment-28791"> <div id="dsq-comment-header-28791" class="dsq-comment-header"> <cite id="dsq-cite-28791"> <span id="dsq-author-user-28791">Spiff Dog</span> </cite> </div> <div id="dsq-comment-body-28791" class="dsq-comment-body"> <div id="dsq-comment-message-28791" class="dsq-comment-message"><p>Just outta curiousity, are they putting that class in the HtmlControls or WebControls namespace?</p> </div> </div> </li><!-- #comment-## --> <li class="comment odd alt thread-odd thread-alt depth-1" id="dsq-comment-28792"> <div id="dsq-comment-header-28792" class="dsq-comment-header"> <cite id="dsq-cite-28792"> <span id="dsq-author-user-28792">miseldine</span> </cite> </div> <div id="dsq-comment-body-28792" class="dsq-comment-body"> <div id="dsq-comment-message-28792" class="dsq-comment-message"><p>Andre: You need to set the page title tag as with .NET 2.0 (i.e. with a runat=”server”) but define the following in your codebehind:</p> <p><code><br /> Protected pageTitle As System.Web.UI.HtmlControls.HtmlGenericControl</p> <p> Private Sub Page_Load(ByVal sender As System.Object, _<br /> ByVal e As System.EventArgs) Handles MyBase.Load</p> <p> pageTitle.InnerText = "Title"</p> <p> End Sub</code> <p>Spiff Dog: Its a string property on the Page class…</p> <p>“this.” is just an easy way of referencing the current instance :) So, its the System.Web.UI.Page class technically :P</p> </div> </div> </li><!-- #comment-## --> <li class="comment even thread-even depth-1" id="dsq-comment-28793"> <div id="dsq-comment-header-28793" class="dsq-comment-header"> <cite id="dsq-cite-28793"> <span id="dsq-author-user-28793">essive</span> </cite> </div> <div id="dsq-comment-body-28793" class="dsq-comment-body"> <div id="dsq-comment-message-28793" class="dsq-comment-message"><p>Creating all of that code just for a title, of course, really doesn’t buy you much. You should really consider placing page titles, descriptions and keywords in the web.config file user defined section such as:<br /> <webpages><br /> <contact .aspx><br /> <add key="title" value="About Us"></add><br /> <add key="desc" value="Contact information about our company!"></add><br /> </contact><br /> </webpages></p> <p>and then reference this using the script name from the web pages. This allows easy page editing in a single file.</p> </div> </div> </li><!-- #comment-## --> </ul> </div> </div> <script type="text/javascript"> var disqus_url = ''; var disqus_identifier = '38518 http://492824695'; var disqus_container_id = 'disqus_thread'; var disqus_shortname = 'sitepointproduction'; var disqus_title = "Setting Page Titles 2005 Style"; var disqus_config_custom = window.disqus_config; var disqus_config = function () { /* All currently supported events: onReady: fires when everything is ready, onNewComment: fires when a new comment is posted, onIdentify: fires when user is authenticated */ this.language = ''; this.callbacks.onReady.push(function () { // sync comments in the background so we don't block the page var script = document.createElement('script'); script.async = true; script.src = '?cf_action=sync_comments&post_id=38518'; var firstScript = document.getElementsByTagName('script')[0]; firstScript.parentNode.insertBefore(script, firstScript); }); if (disqus_config_custom) {; } }; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + ''; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> </div> <div class="l-pv3 l-mt4"> <premium-latest-listing type="Course" href="/premium/courses/" slug="programming" limit="3"></premium-latest-listing> <premium-latest-listing type="Book" href="/premium/books/" slug="programming" limit="3"></premium-latest-listing> </div> </div> <div class="l-w-aside-i l-mt6 l-mh3 l-d-n l-d-f--3col l-fd-col l-fs0"> <div class="l-mb3"> <div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-1"><!-- SP2013_Articles_300x250_1 size:300,250 --> <div id="div-gpt-ad-1392428092543-0" class="ad-tag " data-ad-name="SP2013_Articles_300x250_1" data-ad-size="300x250"> <script type="text/javascript"> if (typeof window.deployads_disabled === "undefined" || window.deployads_disabled) { window.SP_Adbridg_Slots.push({ id : "1392428092543-0", name : "SP2013_Articles_300x250_1", sizes : [300,250], desktop : 1, tablet : 1, phone : 0 }); } </script> </div> <script src="//" async></script> <script>(deployads = window.deployads || []).push({});</script></div> </div> <sp-heading content="Recommended"></sp-heading> <div class="l-w-100 l-mv3 l-pa3 t-bg-white m-border"> <div> <ul> <li class="l-d-f l-ai-sta lst-s-n l-mb3"> <span class="Article_recommendedListMarker l-d-ib l-fs0 l-mt1 l-round f-center f-small f-c-white t-bg-grey-300">1</span> <a class="l-d-ib l-pl2 f-c-grey-500 f-medium f-bold" href="">Google Maps Made Easy with GMaps.js</a> </li> <li class="l-d-f l-ai-sta lst-s-n l-mb3"> <span class="Article_recommendedListMarker l-d-ib l-fs0 l-mt1 l-round f-center f-small f-c-white t-bg-grey-300">2</span> <a class="l-d-ib l-pl2 f-c-grey-500 f-medium f-bold" href="">Developing Add-ons for Enterprise Apps like JIRA</a> </li> <li class="l-d-f l-ai-sta lst-s-n l-mb3"> <span class="Article_recommendedListMarker l-d-ib l-fs0 l-mt1 l-round f-center f-small f-c-white t-bg-grey-300">3</span> <a class="l-d-ib l-pl2 f-c-grey-500 f-medium f-bold" href="">Shiny, R and HTML: Merging Data Science and Web Development</a> </li> <li class="l-d-f l-ai-sta lst-s-n l-mb3"> <span class="Article_recommendedListMarker l-d-ib l-fs0 l-mt1 l-round f-center f-small f-c-white t-bg-grey-300">4</span> <a class="l-d-ib l-pl2 f-c-grey-500 f-medium f-bold" href="">Using JOINs in MongoDB NoSQL Databases</a> </li> <li class="l-d-f l-ai-sta lst-s-n l-mb3"> <span class="Article_recommendedListMarker l-d-ib l-fs0 l-mt1 l-round f-center f-small f-c-white t-bg-grey-300">5</span> <a class="l-d-ib l-pl2 f-c-grey-500 f-medium f-bold" href="">Web Scraping for Beginners</a> </li> </ul> </div> </div> <sp-heading content="Sponsors"></sp-heading> <div class="l-w-100 l-mv3 t-bg-white m-border"> <ads-weighted widget='75' data='{"fallback":[{"id":"448","weight":"100","randMax":100}]}' fallback=''></ads-weighted> <ads-weighted widget='74' data='{"fallback":[{"id":"449","weight":"100","randMax":100}]}' fallback=''></ads-weighted> <ads-weighted widget='73' data='{"fallback":[{"id":"450","weight":"100","randMax":100}]}' fallback=''></ads-weighted></div> <div class="l-w-100"> <featured-listing slug="programming" limit="2"></featured-listing> </div> <div class="ArticleBox u-premium-preview"><div class="widget maestro maestro-content-type-spad " id="maestro-product-2"><div class="SPAdPanel"> <div class="SPAdPanel_header"> Learn Coding Online </div> <div class="ArticleBox_content"> <div class="SPAdPanel_content"> <div class="SPAdPanel_tagline"><i class="SPAdPanel_icon fa fa-rocket"></i>Learn Web Development</div> <p class="SPAdPanel_creative">Start learning web development and design <b>for free</b> with SitePoint Premium!</p> </div> <div class="SPAdPanel_cta"> <a class="SPAdPanel_ctaButton button" href=>Start Learning Now</a> </div> </div> </div></div></div> <div class="ArticleAside_row ArticleAside_newboxads"><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-177"><!-- SP_Articles_200x125_1 --> <div id="div-gpt-ad-1436815711585-0" style="" class="adspot "> <script type="text/javascript"> window.SP_Adbridg_Slots.push({ id : "1436815711585-0", name : "SP_Articles_200x125_1", sizes : [200,125], desktop : 1, tablet : 1, phone : 0 }); </script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-178"><!-- SP_Articles_200x125_2 --> <div id="div-gpt-ad-1436815711585-1" style="" class="adspot "> <script type="text/javascript"> window.SP_Adbridg_Slots.push({ id : "1436815711585-1", name : "SP_Articles_200x125_2", sizes : [200,125], desktop : 1, tablet : 1, phone : 0 }); </script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-179"><!-- SP_Articles_200x125_3 --> <div id="div-gpt-ad-1436815711585-2" style="" class="adspot "> <script type="text/javascript"> window.SP_Adbridg_Slots.push({ id : "1436815711585-2", name : "SP_Articles_200x125_3", sizes : [200,125], desktop : 1, tablet : 1, phone : 0 }); </script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-180"><!-- SP_Articles_200x125_4 --> <div id="div-gpt-ad-1436815711585-3" style="" class="adspot "> <script type="text/javascript"> window.SP_Adbridg_Slots.push({ id : "1436815711585-3", name : "SP_Articles_200x125_4", sizes : [200,125], desktop : 1, tablet : 1, phone : 0 }); </script> </div></div></div> <div class="ArticleAside_row"><div class="widget maestro maestro-content-type-html hide-for-tablet-SP hide-for-mobile-SP" id="maestro-product-93"><adblock-carbon data-src="//"></adblock-carbon></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-49"><!-- SP2013_Articles_300x600_1 size:[300, 600], [300, 250], [160, 600] --> <div id="div-gpt-ad-1392428092543-4" class="ad-tag Sticky" data-ad-name="SP2013_Articles_300x600_1" data-ad-size="300x600"> <script type="text/javascript"> if (typeof window.deployads_disabled === "undefined" || window.deployads_disabled) { window.SP_Adbridg_Slots.push({ id : "1392428092543-4", name : "SP2013_Articles_300x600_1", sizes : [[300, 600], [300, 250], [160, 600]], desktop : 1, tablet : 1, phone : 0 }); } </script> </div> <script src="//" async></script> <script>(deployads = window.deployads || []).push({});</script></div></div> </div> </div> <div class="u-accordion-end"></div> <category-subscribe slug="programming"></category-subscribe> <article-sharer data-url="" data-title="Setting Page Titles 2005 Style"></article-sharer> </div> </div> <div class="widget maestro maestro-content-type-html hide-for-mobile-SP" id="maestro-product-135"><script type="text/html" class=" ModalOnce" data-activate-delay=5 data-tracking="ebookbundlerefresh" data-min-height="550" data-min-width="400" data-tracking-days="14"> <div id="ebookbundlerefresh-modal" class="reveal-modal" data-reveal aria-labelledby="10 free SitePoint ebooks" aria-hidden="true" role="dialog"> <form method="get" action="" style="padding: 1em; text-align: center;"> <input type="hidden" name="utm_source" value="sitepoint" /> <input type="hidden" name="utm_medium" value="modal" /> <input type="hidden" name="utm_campaign" value="ebookbundle" /> <div style="font-size: 48px; font-weight: bold; line-height: 1.3;">10 free SitePoint ebooks</div> <div class="emoji" style="font-size: 24px; font-weight: 300; line-height: 1.3; color: #6f6f6f;"> Just because we like you </div> <div style="margin-top: 4em; margin-bottom: 1em;"> <input class="Button" type="submit" value="Claim Your Ebooks Now!" /> </div> <div style="font-weight: 300; line-height: 1.3; color: #a2a2a2;">Totally free. No credit card required.</div> <img style="max-width: 100%; margin-top: 4em;" src="" /> </form> <a class="close-reveal-modal" aria-label="Close">×</a> </div> </script> <style> #ebookbundle-modal { max-width: 900px; left: 0; right: 0; margin: auto; position: fixed; top: 100px !important; } #ebookbundle-modal .Button { font-weight: bold; font-size: 1.25rem; padding: 0.75em; border-color: #38c9cb; border-bottom-color: #189697; border-bottom-width: thick; background-color: #38c9cb; line-height: 1; } #ebookbundle-modal .Button:hover { border-color: #24b3b5; background-color: #24b3b5; } #ebookbundle-modal .emoji::before { content: ' \1f4da'; } #ebookbundle-modal .emoji::after { content: '\1f604'; } </style></div> <footer class="Footer" role="contentinfo"> <div class="Footer_container"> <ul class="FooterList"> <li class="FooterList_item"> <h3>About</h3> </li> <li class="FooterList_item"> <a href="/about-us/">Our Story</a> </li> <li class="FooterList_item"> <a href="/advertise/">Advertise</a> </li> <li class="FooterList_item"> <a href="/press/">Press Room</a> </li> <li class="FooterList_item"> <a href="" target="_blank">Reference</a> </li> <li class="FooterList_item"> <a href="/legals/">Terms of Use</a> </li> <li class="FooterList_item"> <a href="/legals/#privacy">Privacy Policy</a> </li> <li class="FooterList_item"> <a href="" target="_blank">FAQ</a> </li> <li class="FooterList_item"> <a href="">Contact Us</a> </li> <li class="FooterList_item"> <a href="/write-for-us/">Contribute</a> </li> </ul> <ul class="FooterList"> <li class="FooterList_item"> <h3>Visit</h3> </li> <li class="FooterList_item"> <a href="/">SitePoint Home</a> </li> <li class="FooterList_item"> <a href="">Forums</a> </li> <li class="FooterList_item"> <a href="/newsletter/">Newsletters</a> </li> <li class="FooterList_item"> <a href="/premium/">Premium</a> </li> <li class="FooterList_item"> <a href="/sass-reference/">References</a> </li> <li class="FooterList_item"> <a href="">Shop</a> </li> <li class="FooterList_item"> <a href="">Versioning</a> </li> </ul> <ul class="FooterList"> <li class="FooterList_item"> <h3>Connect</h3> </li> <li class="FooterList_item FooterList_item--icons"> <a href=""> <i class="fa fa-rss-square"></i> </a> <a href="/newsletter/"> <i class="fa fa-envelope-square"></i> </a> <a href="" target="_blank"> <i class="fa fa-facebook-square"></i> </a> <a href="" target="_blank"> <i class="fa fa-twitter-square"></i> </a> <a href="" target="_blank"> <i class="fa fa-google-plus-square"></i> </a> </li> <p class="Footer_copyright"> © 2000 – 2016 SitePoint Pty. Ltd. </p> </ul> </div> </footer> <script type="text/javascript"> adroll_adv_id = "DJI3I3WGJBGL7PDJEDAYHV"; adroll_pix_id = "4RKMV6N56FGA7ANPGL4FQW"; (function () { document.createElement('adblock-carbon'); var adblockCarbon = false; var onAdblock = function() { if(adblockCarbon) return; adblockCarbon = true; gaEventQueue && gaEventQueue.track('CanSeeAds', 'adrollBlocked', {'nonInteraction': true});'CantSeeAds')) .forEach(function(el) { el.className = el.className.replace('CantSeeAds', ''); }); var node = document.getElementsByTagName('adblock-carbon')[0]; if (!node) return; var carbon = document.createElement('script'); carbon.async = true; = '_carbonads_js'; carbon.type = 'text/javascript'; carbon.src = node.getAttribute('data-src'); node.parentNode.insertBefore(carbon, node); }; var _onload = function(){ if (document.readyState && !/loaded|complete/.test(document.readyState)){setTimeout(_onload, 10);return} if (!window.__adroll_loaded){__adroll_loaded=true;setTimeout(_onload, 50);return} var scr = document.createElement("script"); var host = (("https:" == document.location.protocol) ? "" : ""); scr.setAttribute('async', 'true'); scr.type = "text/javascript"; scr.src = host + "/j/roundtrip.js"; scr.onerror = onAdblock; ((document.getElementsByTagName('head') || [null])[0] || document.getElementsByTagName('script')[0].parentNode).appendChild(scr); }; if (window.addEventListener) {window.addEventListener('load', _onload, false);} else {window.attachEvent('onload', _onload)} }()); </script> <script> (function(d,b,a,s,e){ var t = b.createElement(a), fs = b.getElementsByTagName(a)[0]; t.async=1;; t.src=s; fs.parentNode.insertBefore(t, fs); }) (window,document,'script','','demandbase_js_lib'); </script> <script type='text/javascript'><!-- var seriesdropdown = document.getElementById("orgseries_dropdown"); if (seriesdropdown) { function onSeriesChange() { if ( seriesdropdown.options[seriesdropdown.selectedIndex].value != ( 0 || -1 ) ) { location.href = ""+seriesdropdown.options[seriesdropdown.selectedIndex].value; } } seriesdropdown.onchange = onSeriesChange; } --></script> <script type="text/javascript"> // <![CDATA[ var disqus_shortname = 'sitepointproduction'; (function () { var nodes = document.getElementsByTagName('span'); for (var i = 0, url; i < nodes.length; i++) { if (nodes[i].className.indexOf('dsq-postid') != -1) { nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('data-dsqidentifier')); url = nodes[i].parentNode.href.split('#', 1); if (url.length == 1) { url = url[0]; } else { url = url[1]; } nodes[i].parentNode.href = url + '#disqus_thread'; } } var s = document.createElement('script'); s.async = true; s.type = 'text/javascript'; s.src = '//' + disqus_shortname + ''; (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); }()); // ]]> </script> <!-- START Include: Standard --> <div id="parsely-root" style="display: none"> <div id="parsely-cfg" data-parsely-site=""></div> </div> <script data-cfasync="false"> (function(s, p, d) { var h=d.location.protocol, i=p+"-"+s, e=d.getElementById(i), r=d.getElementById(p+"-root"), u=h==="https:"?"" :"static."+p+".com"; if (e) return; e = d.createElement(s); = i; e.async = true; e.setAttribute('data-cfasync', 'false'); e.src = h+"//"+u+"/p.js"; r.appendChild(e); })("script", "parsely", document); </script> <!-- END Include: Standard --> <script type="text/javascript"> (function(AdBridg, SP_Adbridg_Slots, matchMedia) { if(!SP_Adbridg_Slots.length) return; var SP_Adbridg_All_Slots_Count = SP_Adbridg_Slots.length; var SP_Adbridg_Displayed_Slots = 0; var SP_Adbridg_First_Slot_Rendered = false; AdBridg.cmd.push(function(){ googletag.pubads().addEventListener("slotRenderEnded", function(e){ if (!SP_Adbridg_First_Slot_Rendered) { gaEventQueue.track("CanSeeAds", "dfpFirstRendered", {"nonInteraction": true}); SP_Adbridg_First_Slot_Rendered = true; } SP_Adbridg_Displayed_Slots--; if(SP_Adbridg_Displayed_Slots===0) { gaEventQueue.track("CanSeeAds", "dfpAllRendered", {"nonInteraction": true}); } }); }); if(matchMedia) { var phoneMq = matchMedia("(max-width: 768px)"); var tabletMq = matchMedia("(min-width: 769px) and (max-width: 1024px)"); var desktopMq = matchMedia("(min-width: 1025px)"); phoneMq.addListener(checkSlots); tabletMq.addListener(checkSlots); desktopMq.addListener(checkSlots); checkSlots({matches: true, media: "initial"}); } else { // display all slots for old browsers var i = 0; var len = SP_Adbridg_Slots.length; for(; i < len; i++) { displaySlot(SP_Adbridg_Slots[i]); } SP_Adbridg_Slots = []; AdBridg.cmd.push(function() { AdBridg.serve(); }); } function checkSlots(mq) { if(!mq.matches || !SP_Adbridg_Slots.length) return; SP_Adbridg_Slots = SP_Adbridg_Slots.reduce(function(acc, slot){ if ( ( && phoneMq.matches) || (slot.tablet && tabletMq.matches) || (slot.desktop && desktopMq.matches) ) { displaySlot(slot); } else { acc.push(slot); } return acc; }, []); if(SP_Adbridg_Slots.length < SP_Adbridg_All_Slots_Count) { phoneMq.removeListener(checkSlots); tabletMq.removeListener(checkSlots); desktopMq.removeListener(checkSlots); } AdBridg.cmd.push(function() { AdBridg.serve(); }); } function displaySlot(slot) { AdBridg.cmd.push(function(){ AdBridg.defineSlot("/7448792/" +, slot.sizes, "div-gpt-ad-" +; AdBridg.display("div-gpt-ad-" +; }); SP_Adbridg_Displayed_Slots++; } })(AdBridg, SP_Adbridg_Slots, window.matchMedia); </script> <script type='text/javascript' src='//'></script> <script type='text/javascript' src='//'></script> <script type='text/javascript' src=''></script> <script> jQuery(document).ready(function() { jQuery('.lazyYT').each(function() { var id = jQuery(this).data('youtube-id'), url = '' + id; jQuery(this).replaceWith('<a href="' + url + '">' + url + '</a>'); }); }); </script> </body> </html> <!-- Performance optimized by W3 Total Cache. Learn more: Page Caching using memcached Object Caching 1161/1195 objects using memcached Content Delivery Network via Amazon Web Services: CloudFront: Served from: @ 2016-10-22 18:54:44 by W3 Total Cache -->