Setting Page Titles 2005 Style

Tweet

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> </section> <div class="article__author-bios"> <div class="contributor contributor--large"> <figure class="contributor_avatar"> <a href="http://www.sitepoint.com/author/philip-miseldine/"> <img alt='' src='http://0.gravatar.com/avatar/ac68fbf57913531cc509000d75beddab?s=96&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&r=G' class='avatar avatar-96 photo' height='96' width='96' /> </a> </figure> <div class="contributor_details"> <div class="contributor_name"> <a href="http://www.sitepoint.com/author/philip-miseldine/">Philip Miseldine</a> </div> <p class="contributor_longdesc">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="http://www.miseldine.com/">http://www.miseldine.com/</a>.</p> <ul class="contributor_social"> </ul> </div> </div> </div> <div class="related-content"> <h2>You might also like:</h2> <ul class="article-list article-list--related"> <li class="article-list_item tile post-tile"> <article class="article article--micro article--micro--related category-php " data-disqus-id="http://www.sitepoint.com/autogenerate-crud-apps-phreeze/"> <header class="article_category"><h2 class="article_category_title"><a href="http://www.sitepoint.com/php/">PHP</a></h2></header> <section class="article_header"> <h1 class="article_title"><a href="http://www.sitepoint.com/autogenerate-crud-apps-phreeze/">Autogenerate CRUD Apps with Phreeze</a></h1> <div class="contributor article_contributor"> <p class="contributor_name article_author-name">by <a href="http://www.sitepoint.com/author/tren/">Taylor Ren</a></p> </div> <div class="article_meta-data"><p class="article_pub-date"><time datetime="2014-05-29 09:00:09" pubdate>May 29, 2014</time></p></div> </section> </article> </li> <div class="widget maestro maestro-content-type-html " id="maestro-product-15"><li class="article-list_item tile post-tile"> <article class="article article--micro article--micro--related category-web"> <header class="article_category"><h2 class="article_category_title"><a href="https://learnable.com?utm_source=sitepoint&utm_medium=related-items&utm_content=js-bootstrap">Learnable</a></h2></header> <section class="article_header"> <h1 class="article_title"><a href="https://learnable.com/books/jump-start-bootstrap?utm_source=sitepoint&utm_medium=related-items&utm_content=js-bootstrap">Book: Jump Start Bootstrap</a></h1> <div class="contributor article_contributor"> <p class="contributor_name article_author-name">by <a href="http://www.sitepoint.com/author/sfrahman/">Syed Fazle Rahman</a></p> </div> <div class="article_meta-data"><p class="article_pub-date">PREMIUM</p></div> </section> </article> </li></div> <li class="article-list_item tile post-tile"> <article class="article article--micro article--micro--related category-php " data-disqus-id="http://www.sitepoint.com/introduction-views-3-drupal-7/"> <header class="article_category"><h2 class="article_category_title"><a href="http://www.sitepoint.com/php/">PHP</a></h2></header> <section class="article_header"> <h1 class="article_title"><a href="http://www.sitepoint.com/introduction-views-3-drupal-7/">Introduction to Views 3 in Drupal 7</a></h1> <div class="contributor article_contributor"> <p class="contributor_name article_author-name">by <a href="http://www.sitepoint.com/author/dsipos/">Daniel Sipos</a></p> </div> <div class="article_meta-data"><p class="article_pub-date"><time datetime="2014-05-10 09:00:25" pubdate>May 10, 2014</time></p></div> </section> </article> </li> </ul> </div> <div class="promo-panel"> <div class="widget maestro maestro-content-type-product " id="maestro-product-29"><div class="promo-panel_media-object"><img src="https://d2sis3lil8ndrq.cloudfront.net/books/jshtml-basics1_medium_3d.png" /></div> <div class="promo-panel_content"> <h1 class="promo-panel_title"> Free book: Jump Start HTML5 Basics </h1> <p>Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.</p> <form class="promo-panel_action"><input type="email" name="email" class="promo-panel_email" placeholder="email address" /><input type="hidden" name="content" value="29" /><button class="button radius">Claim Book</button></form> </div></div> </div> <div class="widget maestro maestro-content-type-ad hide-for-desktop-SP hide-for-tablet-SP" id="maestro-product-51"><!-- SP2013_Articles_320x50_2 --> <div id="div-gpt-ad-1392428092543-6" style="width:320px; height:50px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1392428092543-6"); });</script> </div></div> <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"> http://www.spiffdog.com <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"> http://www.miseldine.com <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"> http://www.webprofessionaltemplates.com <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"> /* <![CDATA[ */ var disqus_url = 'http://www.sitepoint.com/setting-page-titles-2005-style/'; var disqus_identifier = '38518 http://492824695'; var disqus_container_id = 'disqus_thread'; var disqus_domain = 'disqus.com'; var disqus_shortname = 'sitepointproduction'; var disqus_title = "Setting Page Titles 2005 Style"; var disqus_config = function () { var config = this; // Access to the config object config.language = ''; /* All currently supported events: * preData — fires just before we request for initial data * preInit - fires after we get initial data but before we load any dependencies * onInit - fires when all dependencies are resolved but before dtpl template is rendered * afterRender - fires when template is rendered but before we show it * onReady - everything is done */ config.callbacks.preData.push(function() { // clear out the container (its filled for SEO/legacy purposes) document.getElementById(disqus_container_id).innerHTML = ''; }); config.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); }); }; /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ var DsqLocal = { 'trackbacks': [ ], 'trackback_url': "http:\/\/www.sitepoint.com\/setting-page-titles-2005-style\/trackback\/" }; /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.' + 'disqus.com' + '/embed.js?pname=wordpress&pver=2.74'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); /* ]]> */ </script> </article> </div> <aside class="page_aside article_aside"> <div class="adrow--top"> <div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-1"><!-- SP2013_Articles_300x250_1 --> <div id="div-gpt-ad-1392428092543-0" style="width:300px; height:250px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1392428092543-0"); });</script> </div></div> </div> <div class="adrow--middle"> <div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-172"><!-- Sitepoint_125x125 --> <div id="div-gpt-ad-1400800012700-0" style="width:125px; height:125px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1400800012700-0"); });</script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-166"><!-- Sitepoint_125x125_2 --> <div id="div-gpt-ad-1400782268851-0" style="width:125px; height:125px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1400782268851-0"); });</script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-167"><!-- Sitepoint_125x125_3 --> <div id="div-gpt-ad-1400782991292-0" style="width:125px; height:125px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1400782991292-0"); });</script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-168"><!-- Sitepoint_125x125_4 --> <div id="div-gpt-ad-1400783440189-0" style="width:125px; height:125px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1400783440189-0"); });</script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-169"><!-- Sitepoint_125x125_5 --> <div id="div-gpt-ad-1400783664460-0" style="width:125px; height:125px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1400783664460-0"); });</script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-170"><!-- Sitepoint_125x125_6 --> <div id="div-gpt-ad-1400783847643-0" style="width:125px; height:125px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1400783847643-0"); });</script> </div></div> </div> <div class="adrow--bottom"> <div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-48"><!-- SP2013_Articles_300x250_4 --> <div id="div-gpt-ad-1392428092543-3" style="width:300px; height:250px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1392428092543-3"); });</script> </div></div><div class="widget maestro maestro-content-type-ad hide-for-mobile-SP" id="maestro-product-49"><!-- SP2013_Articles_300x600_1 --> <div id="div-gpt-ad-1392428092543-4" style="width:300px; height:600px;" class="adspot"> <script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1392428092543-4"); });</script> </div></div> </div> </aside> </main> <footer class="site-footer" role="contentinfo"> <div class="row"> <ul class="footer-links"> <li class="foot-link_item"> <h3>About</h3> </li> <li class="foot-link_item"> <a href="/about-us/">About us</a> </li> <li class="foot-link_item"> <a href="/advertising">Advertise</a> </li> <li class="foot-link_item"> <a href="/press">Press Room</a> </li> <li class="foot-link_item"> <a href="/legals">Legals</a> </li> <li class="foot-link_item"> <a href="mailto:feedback@sitepoint.com">Feedback</a> </li> <li class="foot-link_item"> <a href="/write-for-us">Write for Us</a> </li> </ul> <ul class="footer-links"> <li class="foot-link_item"> <h3>Our Sites</h3> </li> <li class="foot-link_item"> <a href="https://learnable.com" target="_blank">Learnable</a> </li> <li class="foot-link_item"> <a href="http://reference.sitepoint.com" target="_blank">Reference</a> </li> <li class="foot-link_item"> <a href="/web-foundations/">Web Foundations</a> </li> </ul> <ul class="footer-links"> <li class="foot-link_item"> <h3>Connect</h3> </li> <li class="foot-link_item foot-link_item--icons"> <a href="/feed"><i class="icon-rss icon-blocks icon-blocks--rss"></i></a> <a href="/newsletter"><i class="icon-envelope-alt icon-blocks icon-blocks--newsletter"></i></a> <a href="https://www.facebook.com/sitepoint" target="_blank"><i class="icon-facebook icon-blocks icon-blocks--facebook"></i></a> <a href="http://twitter.com/sitepointdotcom" target="_blank"><i class="icon-twitter icon-blocks icon-blocks--twitter"></i></a> <a href="https://plus.google.com/+sitepoint" target="_blank"><i class="icon-google-plus icon-blocks icon-blocks--google-plus"></i></a> </li> </ul> <p class="site-footer_copyright"> © 2000 – 2014 SitePoint Pty. Ltd. </p> </div> </footer> <div id="search-dropdown"> <div data-role="search-for"> <a class="search-link" href="#">Search for...</a> </div> <ul data-role="results"></ul> </div> <script type='text/javascript'><!-- var seriesdropdown = document.getElementById("orgseries_dropdown"); if (seriesdropdown) { function onSeriesChange() { if ( seriesdropdown.options[seriesdropdown.selectedIndex].value != ( 0 || -1 ) ) { location.href = "http://www.sitepoint.com/series/"+seriesdropdown.options[seriesdropdown.selectedIndex].value; } } seriesdropdown.onchange = onSeriesChange; } --></script> <div id="triggered-cta-box-wrapper" class="triggered-cta-box-wrapper triggered-cta-box-wrapper--bottom"><a href="#close" id="triggered-cta-box-close">x</a></div> <script type="text/javascript"> (function () { var variant = (Math.random() < 0.5 ? "a" : "b"); var boxContents = { a: '<div class="triggered-cta-box campaign-free-ebook"> <div class="campaign-free-ebook__row1" style="max-width:40em"> <div class="campaign-free-ebook__row1__column1" style="margin-left:1em;width:60%"> <p class="logo-wrapper"><img src="http://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2014/02/1392770725sp-logo-42x50.png" alt="SitePoint logo" /></p> <h1>Get 50% Off Learnable and Help the Penguin Foundation!</h1> <p>This is your chance to access all SitePoint books and courses for two years for just $144, <em>plus</em> help us raise $50,000 for the Penguin Foundation!</p> </div> <div class="campaign-free-ebook__row1__column2"style="width:35%"> <img class="books-image" src="http://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2014/12/1417752395penguin_sitepoint.jpg" alt="Penguin holding a SitePoint sign" /> </div> </div> <div class="campaign-free-ebook__row2"> <form> <div align="center" class="campaign-free-trial-v2__row2"> <a class="submit-btn btn-buy button" href="http://www.sitepoint.com/christmas-sale-1/" style="margin-bottom: 0px;">Get 50% Off Now!</a> </div> <div class="campaign-free-ebook__row2__div2"> <div class="campaign-free-ebook__row2__div2__column1"> <p id="triggered-cta-box-message"></p> </div> </div> </form> </div></div>', b: '<div class="triggered-cta-box campaign-free-ebook"> <div class="campaign-free-ebook__row1" style="max-width:40em"> <div class="campaign-free-ebook__row1__column1" style="margin-left:1em;width:60%"> <p class="logo-wrapper"><img src="http://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2014/02/1392770725sp-logo-42x50.png" alt="SitePoint logo" /></p> <h1>Your first month of Learnable for just $1!</h1> <p>This month only, we\'re dropping the price of your first month of Learnable to $1. That gives you access to all SitePoint books and web development courses!</p> </div> <div class="campaign-free-ebook__row1__column2"style="width:35%"> <img class="books-image" src="http://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2014/12/14189681031dollarslider_360.png" alt="Learnable for $1" /> </div> </div> <div class="campaign-free-ebook__row2"> <form> <div align="center" class="campaign-free-trial-v2__row2"> <a class="submit-btn btn-buy button" href="http://www.sitepoint.com/christmas-sale-13/?utm_source=SitePoint&utm_medium=Slider&utm_campaign=1dollarslider" style="margin-bottom: 0px;">Start Learning Now</a> </div> <div class="campaign-free-ebook__row2__div2"> <div class="campaign-free-ebook__row2__div2__column1"> <p id="triggered-cta-box-message"></p> </div> </div> </form> </div></div>' }; var campaigns = { a: "sitepoint-penguin-slideup", b: "learnable-dollar-slideup" }; var triggeredCtaBoxWrapperEl = document.getElementById("triggered-cta-box-wrapper"); var boxContentsEl = document.createElement("div"); boxContentsEl.innerHTML = boxContents[variant]; triggeredCtaBoxWrapperEl.appendChild(boxContentsEl); window.triggeredCtaBox = { variant: variant, boxSelector: "#triggered-cta-box-wrapper", bgSelector: ".triggered-cta-box-wrapper-bg", closeSelector: "#triggered-cta-box-close", closeLinkSelector: ".triggered-cta-box-close-link", campaign: campaigns[variant], boxType: "bottom", mobileEnabled: false, cookieLife: 14, triggerType: "scroll", triggerRequiredPages: 0, triggerValue: 25, slideSpeed: 1000, ajaxUrl: "https://www.sitepoint.com/wp-admin/admin-ajax.php" }; })(); </script> <!--Plugin WP Missed Schedule 2013.1231.2013 Active - Tag 6707293c0218e2d8b7aa38d418ffa608--> <!-- This site is patched which an important unfixed problem since WordPress 2.5+ to 3.9+ --> <!-- START Parse.ly Include: Standard --> <div id="parsely-root" style="display: none"> <div id="parsely-cfg" data-parsely-site="sitepoint.com"></div> </div> <script> (function(s, p, d) { var h=d.location.protocol, i=p+"-"+s, e=d.getElementById(i), r=d.getElementById(p+"-root"), u=h==="https:"?"d1z2jf7jlzjs58.cloudfront.net" :"static."+p+".com"; if (e) return; e = d.createElement(s); e.id = i; e.async = true; e.src = h+"//"+u+"/p.js"; r.appendChild(e); })("script", "parsely", document); </script> <!-- END Parse.ly Include: Standard --> <script type='text/javascript' src='//www.sitepoint.com/wp-content/themes/sitepoint/assets/javascripts/scripts-foot-1fff1067b547366e2ddc5d3cb9d0cb1f.js?ver=4.0'></script> <script> $(document).ready(function() { $(".article_header__buttons .sp-twitter-share-button").on("click", function (evt) { evt.preventDefault(); var url = "https://twitter.com/intent/tweet?" + $.param({ url: "http://www.sitepoint.com/setting-page-titles-2005-style/", text: "Setting Page Titles 2005 Style", via: "sitepointdotcom" }); var popupWidth = 550, popupHeight = 420, screenWidth = screen.width, screenHeight = screen.height, popupLeftOffset = Math.round(screenWidth / 2 - popupWidth / 2), popupTopOffset = 0; if (screenHeight > popupHeight) { popupTopOffset = Math.round(screenHeight / 2 - popupHeight / 2); } window.open(url, null, "scrollbars=yes,resizable=yes,toolbar=no,location=yes" + ", width=" + popupWidth + ", height=" + popupHeight + ", left=" + popupLeftOffset + ",top=" + popupTopOffset); }); }); </script><script> $(document).ready(function() { $(".article_header__buttons .subscribe-button").on("click", function (evt) { evt.preventDefault(); var url = evt.target.href; var popupWidth = 550, popupHeight = 720, screenWidth = screen.width, screenHeight = screen.height, popupLeftOffset = Math.round(screenWidth / 2 - popupWidth / 2), popupTopOffset = 0; if (screenHeight > popupHeight) { popupTopOffset = Math.round(screenHeight / 2 - popupHeight / 2); } window.open(url, null, "scrollbars=yes,resizable=yes,toolbar=no,location=yes" + ", width=" + popupWidth + ", height=" + popupHeight + ", left=" + popupLeftOffset + ",top=" + popupTopOffset); }); }); </script><script>(function($){$(document).ready(function(){ if(typeof DISQUSWIDGETS != "undefined"){DISQUSWIDGETS.loadCount($, "sitepointproduction")} });})(jQuery);</script> </body> </html> <!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/ Page Caching using memcached Object Caching 860/927 objects using memcached Content Delivery Network via Amazon Web Services: CloudFront: dab1nmslvvntp.cloudfront.net Served from: www.sitepoint.com @ 2014-12-26 03:37:22 by W3 Total Cache -->