Reputation: 14253
I have this Master page code near <title>
:
<title>
<asp:ContentPlaceHolder ID="title" runat="server">
</asp:ContentPlaceHolder>
</title>
and in a web form that use this Master page I have this code:
<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
</asp:Content>
How can I add some part of title
of page in Master page code behind and other part of title
in web form code behind that use this Maser page?
since <title>
does not accept inner tag ;I cant use some <div>
to solve this.
Upvotes: 1
Views: 1120
Reputation: 919
If I understand you correct, you would like to set the page title as combination of strings coming from the master page code behind and the content page code behind, right?
I would not use an asp:Content
placeholder for that, but instead an asp:Literal
.
This means you would need the following:
MasterPage.Master:
<title>
<asp:Literal ID="TitleLiteral" runat="server"></asp:Literal>
</title>
MasterPage.Master.cs:
public void SetTitle(string text)
{
TitleLiteral.Text = "my part of the title from master page" + text;
};
ContentPage.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
((MasterPage)Master).SetTitle("My part of the title from content page");
};
where MasterPage
is the name of your master page (public partial class MasterPage: System.Web.UI.MasterPage
).
Upvotes: 2