I need to set the page title dynamically, so I am using code similar to the following:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="~/about.aspx.cs" Inherits="Default" %>
<%@ Register Assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<%@ MasterType VirtualPath="MasterPage.master" %>
<%@ OutputCache Duration="43200" VaryByParam="*" Location="Server" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<title><%=pageTitle%></title>
</asp:Content>
But this creates duplicate header tags. Is there any way around this? Thanks.
EDIT: Following the suggestions below, I now have the following in my MasterPage:
<head id="Head1" runat="server">
<title>Default Title</title>
...
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
and on my main page:
this.Title="xxx";
but I get no name (neither "Default Header" nor "xxx").
EDIT: Nevermind. Using this method, it worked.
source
share