Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page.Title vs Title tag in asp.net

Tags:

I am using asp.net. I have noticed that we can configure page title (static and dynamic both) in two ways:

  1. We have a Title attribute in the page directive:

      <%@ Page Language="C#" Inherits="_Default"  Title="My Title" ......%> 
  2. 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 ?

like image 247
Arshad Avatar asked Oct 07 '13 12:10

Arshad


People also ask

Is page title the same as title tag?

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.

Whats the difference between a Web page's title and a heading on the 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.

Should H1 be site title or page title?

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).

What is a page title?

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.


1 Answers

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.

like image 138
walther Avatar answered Oct 19 '22 05:10

walther