Maintaining a permanent website name

If I create a website in ASP.NET, is it possible to programmatically set the page title to some predefined value with some additional information that needs to be referenced? For instance:

Home Page Title = Site Name Links Title = Site Name: Links Stuff Title = Site Name: Stuff 

Basically, no matter what I called the main heading on the page I'm currently on, I want to back up the ": Name" at the end of the heading so that it remains consistent on the website. I thought about defining it as a ContentPlaceHolder and wrapping some logic around it, but it doesn't seem to work as I thought it would (AKA, not at all).

+4
source share
5 answers

While Lerkst's answer will work for ASP.NET Webforms, I am trying to do this through ASP.NET MVC. As a result, for Site.Master there is no code page for the code (as it should not be). So, after a little research, I came across t my post by Guillaume Roy , which discusses how to use the ActionFilterAttribute to use the controller to configure this data (and the view is β€œdumb” and only displays it). This allows me to embed data in the view and thus do what I wanted to do.

Hope this helps someone else!

0
source

Expression Web has both dynamic web templates (currently my favorites) and master pages. DWT is very easy to use and does exactly what you are looking for in real time. You create one DWT (template page) for the entire site, and then on this page are editable areas that you can edit to make all of your other pages unique. In addition, Expression Web works great with other MS products and features (such as Visual Studio and ASP.NET).

0
source

This may answer your question: 4guysfromrolla link

0
source

try this on the main page

 protected void Page_Load(object sender, EventArgs e) { PreRender += new EventHandler(MasterPage_PreRender); } void MasterPage_PreRender(object sender, EventArgs e) { Page.Title = "Site Name - " + Page.Title; } 

and put the page title in the @Page directive on the content page (title = "Blah" to make it "Site Name - Blah")

0
source

If you use the main page, Lerxst's answer should do this if you cannot use BasePage to accomplish what you want. Something like that:

 public abstract class BasePage : Page { protected abstract string Subtitle { get; } protected BasePage() { Page.Load += (s, e) => { Title = "Site Name: " + Subtitle; }; }} 
0
source

Source: https://habr.com/ru/post/1310280/


All Articles