I am using asp.net. I have noticed that we can configure page title (static and dynamic both) in two ways:
We have a Title
attribute in the page directive:
<%@ Page Language="C#" Inherits="_Default" Title="My Title" ......%>
We also have <title>
tag in the page:
<title runat="server" id="MyTitle"> My Title</title>
Both can be accessed in code-behind file:
MyTitle.Text = "Title from Code behind"; Page.Title = "Page Title from CS";
And i have found the page directive overrides the html title. So Which one should we use and why ?
The main difference between a page title and an h1 tag is that the page title is shown in the browser window and search results snippet while the h1 tag is only shown on the page itself. The page title is defined in the HTML <head> section while the H1 tag is part of the <body> of a page.
The Title tag reflects the general essence of the page including relevant queries and can be used in search results. The H1 header is visible to a user after going to a website.
It's better if H1 tags are contextually related to the majority of the content on the page - so it should really be the page title. If every page has the same H1 tag (i.e. the site title), it degrades the value of them (and overall, they are really the most valuable tag).
Every webpage (e.g. homepage, subpage) has its own title. The page title is laid out in HTML code and appears in the title bar of the browser. Search engines display page titles in their search results. In addition, search engines use page titles in order to recognize what information the website contains.
The biggest difference is that with MyTitle.Text
you have to decorate Title element with an id
AND runat
attributes, and remember it's name so you can reference it. Also accessing this value isn't that easy from child pages when you're using Masterpage for instance..
On the other hand, Page.Title
is common to every Page, so it's more universal in my opinion. Every new developer you'll work with won't have to learn anything new, just use the Page.Title format..
So my vote would go to the "traditional" Page.Title
Whichever you like to use, stick with it, so you won't mix various ways of setting the title. That way you won't have to worry about which event happens first or about your colleague overwriting your values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With