Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Page Title on asp content where it uses master page

Ok this an odd way of doing this, I know I should have done it on Page_Load in every pages when using Masterpage, but is there a way around this issue? I don't want to rebuild the pages if I can help it,if I can only insert a title on <asp:content></asp:content> it would be easier.

If anyone has run into this or maybe have a suggestion of a good way to do it , I know jquery can do it document.title ='' but I heard it's not SEO friendly.

Thanks!

like image 715
PinoyDev Avatar asked Feb 07 '14 01:02

PinoyDev


3 Answers

You can still set the title in each page that's using a MasterPage. In markup: -

<%@ Page Title="Your Title" Language="C#" MasterPageFile="~/_masterpages/... etc

Or in code: -

protected override void OnLoad(EventArgs e)
{
    Page.Title = "Your Title";
    base.OnLoad(e);
}
like image 195
sh1rts Avatar answered Oct 20 '22 16:10

sh1rts


you can place a contentplaceholer in your master page as..

<asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder>

After that In content page add its reference as..

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<title>  Your title goes here.  </title>
</asp:Content>
like image 36
Abhishek Pandey Avatar answered Oct 20 '22 17:10

Abhishek Pandey


more simple solution in Master page <%: Page.Title %> - the main title goes here

in content page first line of it <%@ Page Title="Your Title" Language="C#" MasterPageFile="~/_masterpages/... etc

like image 31
wael Avatar answered Oct 20 '22 18:10

wael