Titel einer ASP.NET-Seite dynamsich ändern

Written on February 23, 2004

Will man den Titel einer ASP.NET-Seite dynamisch ändern, so hat man entweder die Möglichkeit, dies über die von Classic ASP bekannten Delimiter <%%>zu tun, oder aber die saubere Methode per CodeBehind von ASP.NET zu verwenden. Eben diese sei hier kurz vorgestellt.

Hierzu ist in der .aspx-Datei der normale -Tag wie folgt zu ändern:

</title\></p> <p>In der CodeBehind-Datei definiert man dann ein HtmlGenericControl und weißt diesem in der InnerText-Property den gewünschten Seitentitel z.B. in der Page_Load-Methode zu:</p> <p>public System.Web.UI.HtmlControls.HtmlGenericControl mytitle; </p> <p>private void Page_Load(object sender, System.EventArgs e) </p> <p>{ </p> <p> mytitle.InnerText = "Mein dynamischer Seitentitel"; </p> <p>}</p> </div> </div> </div> </article> <div class="container"> <div class="row"> <div id="disqus_thread" class="col-lg-12 col-md-12"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'alexanderzeitlercom'; // required: replace example with your forum shortname /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> </div> </div> <!-- Footer --> <footer> <div class="container"> <div class="row"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <ul class="list-inline text-center"> <li> <a href="http://twitter.com/alexzeitler_"> <span class="fa-stack fa-lg"> <i class="fa fa-circle fa-stack-2x"></i> <i class="fa fa-twitter fa-stack-1x fa-inverse"></i> </span> </a> </li> <li> <a href="http://github.com/alexzeitler"> <span class="fa-stack fa-lg"> <i class="fa fa-circle fa-stack-2x"></i> <i class="fa fa-github fa-stack-1x fa-inverse"></i> </span> </a> </li> </ul> <p class="copyright text-muted">Copyright © Alexander Zeitler 2003 - 2016 | <a href="/impressum.html">Impressum</a></p> </div> </div> </div> </footer> <!-- jQuery --> <script src="/static/js/jquery.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js" ></script> <!-- Bootstrap Core JavaScript --> <script src="/js/bootstrap.min.js"></script> <!-- Custom Theme JavaScript --> <script src="/js/clean-blog.min.js"></script> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-19925241-8', 'auto'); ga('send', 'pageview'); </script> <script>hljs.initHighlightingOnLoad();</script> </body> </html>