Is it possible to append to the Master Page title from the content (child) page
using the HTML file. I know it can be done in the code behind by getting the master page title, and appending to it that way. But isn't there some sort of 'append' property that can be defined in the HTML code for the contentplaceholder?
Example:
Master Page Title: "Organisation Name - "
Content Page: "Contact Us"
So, I want to be able to make the title "Organisation Name - Contact Us" from
within the HTML file, notthe code-behind!
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If headMaster.Title <> "" Then
headMaster.Title = "My Base Title :: " & headMaster.Title ' This bit comes from the Title attribute of the content page...
Else
headMaster.Title = "My Base Title"
End If
Then in the content page just as normal...
<%@ Page Language="VB" MasterPageFile="~/_template.master" AutoEventWireup="false" CodeFile="thispage.aspx.vb" Inherits="thispage" title="This will be appended" %>
This outputs...
<title>My Base Title :: This will be appended</title>
You first remove the Title attribute from page directive of content page, then in page load event of content page add Title = Title + " Content Page Title".
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If headMaster.Title <> "" Then
headMaster.Title = "My Base Title :: " & headMaster.Title ' This bit comes from the Title attribute of the content page...
Else
headMaster.Title = "My Base Title"
End If
This is OK
Then in the content page just as normal...
<%@ Page Language="VB" MasterPageFile="~/_template.master" AutoEventWireup="false" CodeFile="thispage.aspx.vb" Inherits="thispage" title="This will be appended" %>
However this one doesn't work, can you explain how to do this?
Zhao Ji Ma
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Then do the append in the MasterPage code behind (thus avoiding having to add the code to every content page):
Protected Sub Page_Init(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles Me.Init
Me.Page.Title = "SiteName - " &
Me.Page.Title
End Sub
This works really well, is simple and supports easy globalisation; however I have only been coding ASP.NET for three days (moving from ASP classic after 10 years) so there may be downsides I have missed.
Exception Details: System.InvalidOperationException: The resource class for this page was not found. Please check if the resource file exists and try again.
Am I missing a "using system" or something? thanks Si!
Also, you can have another content place holder on the master page, separate from the placeholder for the main content, so you can drop the branch or activity name into the pretty formatted top part of the page.
.
If a post helps to solve your problem, please click the Answer button on that post.
I'm still confused, but now I'm confused on a higher plane.
stevehayter
Member
5 Points
9 Posts
ASP.NET 2.0: Appending To Master Page Title From Content Page
Oct 30, 2006 11:37 AM|LINK
Is it possible to append to the Master Page title from the content (child) page using the HTML file. I know it can be done in the code behind by getting the master page title, and appending to it that way. But isn't there some sort of 'append' property that can be defined in the HTML code for the contentplaceholder?
Example:
Master Page Title: "Organisation Name - "
Content Page: "Contact Us"
So, I want to be able to make the title "Organisation Name - Contact Us" from within the HTML file, not the code-behind!
Thanks
Steve
Master Pages Page Title
joeaudette
Contributor
2984 Points
596 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Oct 30, 2006 07:05 PM|LINK
I think you could make a user control that you could put on your content pages with a property you can set in markup something like this
<myprefix:PageTitleAppender id="PageTitle1" AppendValue=" hey this is appended" runat="server" />
Then in the code behind of the user control you would read the AppendValue, find the MasterPage title and append to it.
I don't know of any other way to do it in markup but this technique means you only have to do the code behind in one place and nothing is hard coded.
Hope it helps,
Joe
http://www.mojoportal.com
ichi
Member
24 Points
9 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Nov 07, 2006 03:11 PM|LINK
Hi, try this...
In the master page...
<HEAD runat="server" id="headMaster">
<title></title>
In the code behind for the master page...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If headMaster.Title <> "" Then
headMaster.Title = "My Base Title :: " & headMaster.Title ' This bit comes from the Title attribute of the content page...
Else
headMaster.Title = "My Base Title"
End If
Then in the content page just as normal...
<%@ Page Language="VB" MasterPageFile="~/_template.master" AutoEventWireup="false" CodeFile="thispage.aspx.vb" Inherits="thispage" title="This will be appended" %>
This outputs...
Girijesh
Contributor
3126 Points
664 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Dec 13, 2006 12:15 PM|LINK
Hi Steve,
You first remove the Title attribute from page directive of content page, then in page load event of content page add Title = Title + " Content Page Title".
Hope this will work.
Thanks,
Girijesh
http://www.girijesh.in/
Zhao Ji Ma -...
All-Star
23104 Points
2380 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Jan 18, 2007 10:46 AM|LINK
The following code works.
1. MasterPage aspx
<%@ Master Language="C#" ...%>
...
<head runat="server" id="headMaster">
<title>Origial Title</title>
</head>
<body>
2. Content page code behind
protected void Page_Load(object sender, EventArgs e)
{
((HtmlHead)Master.FindControl("headMaster")).Title += ":: Append Title";
}
3. Output title
Origial Title:: Append Title
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
JulianMadle
Member
15 Points
6 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Feb 14, 2007 11:12 AM|LINK
My solution to this problem is to use the Title tag of the content page:
<%@ Page Language="VB" MasterPageFile="MasterPage.master" CodeFile="Default.aspx.vb" Inherits="_Default" Title="Home Page" %>
Then do the append in the MasterPage code behind (thus avoiding having to add the code to every content page):
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Me.Page.Title = "SiteName - " & Me.Page.Title
End Sub
This works really well, is simple and supports easy globalisation; however I have only been coding ASP.NET for three days (moving from ASP classic after 10 years) so there may be downsides I have missed.
Girijesh
Contributor
3126 Points
664 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Feb 14, 2007 06:02 PM|LINK
JulianMadle:
I think you had done the same thing that I did.
http://www.girijesh.in/
CSharpSean
Contributor
5464 Points
917 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Mar 08, 2007 02:55 PM|LINK
Just thought i would share this incase anyone else is have this issue: appending localresource to current title:
protected void Page_Load(object sender, EventArgs e)
{
this.Page.Title += " : " + this.GetLocalResourceObject("Title").ToString();
}
//Title is a field in the page's local resource file
blink18jew
Member
199 Points
648 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Jun 02, 2007 12:04 AM|LINK
I added this code :
this.Page.Title += " - " + this.GetLocalResourceObject("New Title").ToString();
and got the error message :
Exception Details: System.InvalidOperationException: The resource class for this page was not found. Please check if the resource file exists and try again.
Am I missing a "using system" or something? thanks Si!
LockH
Contributor
2807 Points
578 Posts
Re: ASP.NET 2.0: Appending To Master Page Title From Content Page
Jun 03, 2007 11:21 AM|LINK
I just include a title or similar in the Page directive on each content page.
Not quite what you asked but an easy solution. Frinstance:
<%
@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Title="ACME Industries: Infinitive Splitting Division" %>Also, you can have another content place holder on the master page, separate from the placeholder for the main content, so you can drop the branch or activity name into the pretty formatted top part of the page.
.
I'm still confused, but now I'm confused on a higher plane.