How to get the default title for a web page?

This seems simple enough and validates it; it really works:

<title>Default text</title> 

On the home page. A:

 <%@ Page Title="Specific name"... 

on a specific page. Or in his code:

 Title = "Specific name"; 

So why am I asking? Since for this I have found all sorts of more complex methods for this. (Yes. At Asp.net.)

So, is there a flaw in the way I wrote above?

+4
source share
2 answers

Not sure what you found, but as usual this is done.
The main page has a default value, with overrides from specific pages.

An alternative (and I don't elaborate on it better) is to use a Content Placeholder.

On the home page

 <title> <asp:ContentPlaceHolder id="PageTitle" runat="server">Default Title</asp:ContentPlaceHolder> </title> 

On a specific page

 <asp:Content ContentPlaceHolderID="PageTitle" runat="server">Specific Title</asp:Content> 

But the disadvantage is that it is not easy to set the header from the code.

+1
source

What you should know here is that <title></title> cannot change from the code behind or from the page declaration if it is not inside the header with runat="server" So, only if you have something:

 <head runat="server"> <title>Default Title</title> </head> 

you can use it by default and then change it on the pages. If the head is not runat = "server", then the code behind cannot find it to change it, and the default name is displayed.

Everything else is the same as them, I also use the same default header on the main page that I change it from the page if I can, or if the default title is not displayed.

+1
source

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


All Articles