Change title text dynamically

[AdSense-A]

So in the past I have changed the title text of my pages from within the code. Not bad just more server side code than probably really needed to be. As I am working on recreating a site and wanting to make sure the titles of each page we unique to that page, plus forgetting how I had made these changes in the past, I did a quick search and ran across this article. These are pretty cool options that I think keep your server side code less muddy and you get the same results. I should mention that I am trying to work towards building sites in MVC so to see this used in MVC coding makes me want to learn more about MVC.

Here is exactly what I used.

On the master page you insert a ContentPlaceHolder and a Literal control inside the title tag:

Then on each of the following pages you add your Content control with the title information:

 

The Literal control is added if you want to make sure that each page has some consistent text. Then the Content control adds on whatever from the new page.

This is pretty cool and helpful  way to change title text dynamically as it keeps this type of information in the aspx page and not in your code. Just one more thing to keep content where it should be.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image

This site uses Akismet to reduce spam. Learn how your comment data is processed.