Custom Page Titles using Masterpages

I am trying to append a custom page title onto a "stock" page title at runtime in the page load.  Something like this:

Content Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Title = "test"
End Sub

Master Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Page.Title = "master title - " & Page.Title
End Sub
 

This page title should render as "master title - test"

This works as expected unless the title attribute of the page tag is set to ""
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test.aspx.vb" Inherits=".test" MasterPageFile="~/MasterPages/Site1.Master" Title="" %>

With this set to "" the title renders as "master title - ", without the custom title appended.

If the title attribute is set to anything else, even a space, the title renders as expected.  It also renders as expected if the title attribute is removed entirely.

The obvious work-around is to just specify default titles or remove the title attribute, but this is still an annoyance as the title attribute renders as "" by default when a new content page is created.  I would say more than half of the dynamic pages that I build override the page title on load, so it's an extra step that I have to do unnessisarily.

As a side note, this behavior only happens (as far as I can tell) when the page title is modified in both the master page and content page.

0
mattsmac56
5/4/2009 2:11:43 PM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

2 Replies
1048 Views

Similar Articles

[PageSpeed] 39

Well, I don't know why that happens (I actually tested it and got the same issue), but you could pass the title to a Session variable instead of setting the content page title directly: 

Content Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Session("Title") = "test"
End Sub

Master Page  

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Page.Title = "master title - " & Session("Title")
End Sub
Perhaps not the "best" solution, but it works.
:. HUGONNE .:
Please mark as answer if the post helps

static void Swap(ref int a, ref int b)
{
//Who said it can't be done without a temporary variable?
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
0
hugonne
5/4/2009 4:12:45 PM

hugonne:

Well, I don't know why that happens (I actually tested it and got the same issue), but you could pass the title to a Session variable instead of setting the content page title directly: 

Content Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Session("Title") = "test"
End Sub
Master Page  
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Page.Title = "master title - " & Session("Title")
End Sub

Perhaps not the "best" solution, but it works.

Yeah, although to be honest, I'd rather just get rid of the page titles.  I like to avoid overusing the session when possible, and the solution I described found is certainly not an overly involved one.

Thanks for testing it for me though.

0
mattsmac56
5/4/2009 4:20:48 PM
Reply:

Similar Artilces:

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

Error Rendering Control ... using the Title property of Page requires a header control on the page. (e.g. <head runat="server" />
Hi All,I have a custom control that inherits from CompositeControl and implements INamingContainer and IPostBackDataHandler.  The control is an intelligent BreadCrumb generator for use on a MasterPage.  It generates LinkButtons for the crumbs based on Server.Transfer() calls to and from ClientPages.Instead of the control rendering as the value of its Text property on the aspx page (which it did when I first started it), I get the following error ***************** Error Rendering Control - ControlNameAn unhandled exception has occurred.Using the Title property of the Page ...

ajax.net controls used in custom composite controls?
I am creating an events calendar that uses the accordion to display the events for the selected day.  The problem I'm having is that the accordion is not responding to any client side events.  I would really like to find a good "How to" article for building composite controls that incorporate an ajax.net control like the accordion....

dynamically setting Html Title of master page from either Controller or ViewPage (Using custom generic type ViewData Not ViewData[""]
Hi,How can I set the html title of my pages dynamically?  I can either do it at the controller or ViewPage level.Note:  I am not using ViewData[""], rather I am using my own strongly typed class that I pass onto my view.Previously people mentioned putting <title><%= ViewData["title"]</title> into my masterpage, but since I am not using ViewData[""] how can I do this now?setting this.Page.Title = "abc123" from within my ViewPage doesn't seem to change the title.My master page looks like:<head runat="server">&...

Creating .Net custom server controls and .Net pages programatically
Thanks a lot for reading this and greatly appreciate your inputs I am writing a webinterface that lets users configure options that'll create an interface for them and generete the webpage. So I am having to programattically create custom server controls and .Net page with code behind to support the functionality. Are there APIs in the .NET SDK that let you do this. Any pointers would be greatly helpful Thanks a lot Sathya Controls on the fly? Or Create code on the fly? I think it is the latter so here we go - look at the following namespaces: * System.Reflection.Emit - gen...

get the current page title from cahced page using a substitution control
Hello, I have a cached product page whose page title is set depending on what product Id is passed in the querystring. I have a substitution control that is not cached and I need this to be able to pick up the page title. As the page is cached I can't use the Page.Title property. Does any one know how I might go about getting it? Many Thanks--------------------------------------------------------Don't forget to click "Mark as Answer" on the post(s) that helped you.NHibernate with ASP.net Problem-Design-Solution sample applicationScott ASP.net blog...

Container reference in custom template control fails when page uses a Master page
Hi, I am trying to create a very simple templated user control.  In fact I've resorted to using an example from MSDN to start with to keep it really simple: http://msdn2.microsoft.com/en-us/library/36574bf6(vs.80).aspxI need to create a similar control that will be happy to be nested in other user controls and within a page templated with a Master page. Inside a normal page and inside nested usercontrols it is perfectly happy. However, when using a master-templated page the Container reference (i.e. <%# Container.Message %>) no longer seems to reference the templated obj...

How do I reference a public property on a page from within a custom control (ascx file) used on that page?
G'day all,You've probably got a quick answer for this  - have a read.In my default.aspx page I have a TabContainer with 6 tab panels. Each tab panel uses a custom control (check.ascx) that I've created which contains a button and some code.When the User clicks the button, the onclick event of the button (handled in the Check.ascx.vb file) must check which tab is active on the Default page and then process accordingly.My problem is that the compile keeps failing because the ActiveTab reference from within the control is not recognised.My Code as follows:Default.aspx : &n...

History control: Navigating away from and "back" to a page using History control.
Hi,Another little issue with the History control.  This one has been racking my brain now for some time, but I think I've narrowed it down to what is actually causing the problem.  My setup: I have a page that is a Repeater (or Gridview, both have this bug) listing of data, that is Paged AND/OR Filtered by a keyword, and is in an UpdatePanel so that it is AJAX style paging and filtering.  I'm using the History control from the May Futures -- the main point of this (and what is mainly broken) is so that when users click on a item in the Repeater and go to the details vi...

code for Custom paging without using sqldatasource control and sql datasource control for gridview...........
 code for Custom paging without using sqldatasource control and sql datasource control for gridview...........i need code for how to show all pagenumbers in gridview with custom paging in gridview..............It is very urgent................................. T.Ashok Kumar  suppose that we have a table like thisCountryId  identity intCountryTitle    nvarchar(50)you can use this sql command for paging the dataUSE [CyberOffice]GO/****** Object:  StoredProcedure [dbo].[CountryGetListPaged]    Script Date: 09/17/2008 14:01:06 ******/SET A...

Using controls from pages, master pages, and user controls
How would I structure my site in this scenario: I'd like to use a dropdownlist all over my site, sometimes in a regular page, sometimes in a master page, and sometimes in a user control.  I wish to bind its events programmatically, so normally I would just put that in the codebehind.  However, I notice a lot of code duplication because I have to declare the control in everywhere, in my base page (which all my pages inherit from), in my base master page (which all my master pages inherit from) and in my base user control (which all my user controls inherit from).How should I be...

Custom navigation pages control. how to?
Hi all. I've a page that can be reached from 10 pages (it's the detail page of a money transaction). I need put a button "back" to return to the caller page. So we have pageA pageB pageC that call pageDetail . In pageDetail I can in pageCustomer, pageBalance, pageDocuments and so on. So... how can I store that pageDetail was called by pageB ? thank you.   Hi, Look into Request.UrlReferrer to see the address of the page that the user was on before coming to the current page. If you need to store more than the previous page (i.e a trail of pages back to where ...

Collection Pager control for custom paging isn't allowing to navigate to the last page programatically.
I downloaded the Collection Pager to implement custom paging for my GridView.  http://www.codeproject.com/KB/custom-controls/CollectionPager.aspx Collection Pager control for custom paging isn't allowing to navigate to the last page programatically. The CurrentPage property I think shuld achieve this, but this is a readonly property. So, I can't set this. Anybody used this control, please let me know how can I navigate to the lat page. This control has certain bugs which I have discovered. Can anybody suggest a better and free custom paging custom/user control for custom...

Net::LDAP::Control::Paged unexpected behavior using multiple paged searches against AD [SEC=UNCLASSIFIED]
------=_NextPart_000_003B_01CEEE7E.0BE685F0 Content-Type: multipart/related; boundary="----=_NextPart_001_003C_01CEEE7E.0BE685F0" ------=_NextPart_001_003C_01CEEE7E.0BE685F0 Content-Type: multipart/alternative; boundary="----=_NextPart_002_003D_01CEEE7E.0BE685F0" ------=_NextPart_002_003D_01CEEE7E.0BE685F0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit UNCLASSIFIED Hi . I am finding unexpected behaviour when using this control against our AD servers. I have tried this using 5.8 (perl-ldap 0.4...

The connection to the server was reset while the page was loading
I have this problem with this download functionality. I'm using a drop down list, and when the user selects an item in that list (selectedindexchanged), a repeater control is automatically binded with the datasource and the repeater is nested in an update panel so no full post back occurs.   The problem is some downloads in the drop down list will not work but others will. The ones that don't work says "The connection to the server was reset while the page was loading," and in IE it just says "Internet Explorer cannot display the web page "   I ...

How do you put a title on a page when using masterpages?
I'm using masterpages. When a user is view my application the tab is "untitled" is there a way to put a title on different pages?  When I try I get an error "only contents are allowed on content pages" You should add the page title in the @Page section (the first line of the file) <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"    CodeFile="Default.aspx.cs" Inherits="Default" Title="Here is my page title" %> ...

using a custom nav control in all my pages
On my Intranet I have two custom controls. One is for navigation and one stores user info. Can someone reveiw this code to see if I my code is efficient? This code is the control is for the displaying user info that is on every page. The control is loaded everytime a page is loaded. ..aspx page <%@ Control Language="c#" AutoEventWireup="false" Codebehind="subNavHome.ascx.cs" Inherits="portal2.controls.subNavHome" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <html> .... </html> Code Behi...

Registering controls in masterpage and use them in pages?
Can one somehow place the register tags of ascx controls in *.master file and use those controls in page (*.aspx) files using that master page? [putting register tags of a control in masterpage doesn't work... :-)] Is it posible? Problems are everywhere... It is time to solve them :] If you want to register controls in one place and use them across a variety of pages, then I would suggest the use of the <controls> section under <pages> under <system.web> in web.config. Controls registered here can be used on any page withough having to add the register directive. ...

Using child page control in masterpage
hi,    i have a listview control in one my child page.In list view control i have a image and checkbox .seleting checkbox i do some operation on database. THere is link button in master page which will insert delete from child page where checkbox are selected. so how can i access child page control in master page.any one can help me.   hi check my post how to access controls in masterpages http://forums.asp.net/p/1330013/2670187.aspx#2670187Please Mark as Answer if it helps you...

Custom paging navigation controls for gridview
Hi, I want to be able to provide a paging navigation control for my gridview similar to below:  <<Prev 1 | 2 | 3 | 4 Next >> But I can't work out how to create the 1 2 3 4 part.  How would I go about doing this?  Is it possible to create like a parent control, and have the 1 2 3 4 part a collection of child controls of hyperlinks (or a label for the currently selected page)?  I'm not sure how this would be done, so any help would be appreciated. good article on a similar way:http://weblogs.asp.net/scottgu/archive/2006/01/07/434787.aspx#4349...

Custom Paging using a Repeater Control
Hello,        After binding the Repeater control to an ObjectDataSource, no data is returned unlike using the Gridview control.  GalleryTableAdapter has the following methods; TotalNumGallery and GetGalleryPagedMethod TotalNumGallery has a query; Select COUNT() from gallery Method GetGalleryPaged has a query from stored procedure;ALTER PROCEDURE dbo.GetGalleryPaged (     @startRowIndex int ,      @maximumRows int )AS    SELECT     idgallery, g_picpath, sdate  &nb...

Custom Control: Calling a function on calling page FROM a custom control ? help !!
I have a custom control placed on many pages, to make things simple, basically what I want to do is Call a function on the calling page from the custom control ieAnyone have any ideas, simple solution would be good !!  This is the code I have myControl.ascx.vbPublic Partial Class myControl    Inherits System.Web.UI.UserControl    Protected Sub testButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles testButton.Click        'call save function on PersonalDetails.aspx.vb  &...

Custom Control to Custom Control communication using event delegate mech.
I have a custom control “AddressPicker” that displays dynamic address information of a user. BY dynamic I mean based on the database call it checks how may addresses a user has and it displays it. There is a “Use this Address” button at the bottom of each address information which is generated dynamically too as a part of CreateChildControl. If a user click on this button I need to pass this information to another custom control namely “AddressConsumer” which in turn uses this information for further processing.My Controls are inherited WebCOntrol,INamingContainer I am using the event deleg...

Problem to use TreeView Control in a 'content page' This Error Occur "Only Content controls are allowed directly in a content page that contains Content controls."
hi I am trying to use the TreeView Control inside the content page (Page that has a master page is a content page). On compiling the project I got the following ASP.Net runtime error: "Only Content controls are allowed directly in a content page that contains Content controls."B@b@R J Issue resolved. I was putting script tag in the content page that is not allowed. when remove the script from content page problem is resolved.B@b@R J...

Web resources about - Custom Page Titles using Masterpages - asp.net.navigation-controls

Chuck Norris - blksthl
... Norris doesn't set an executionpolicy for Powershell. Chuck Norris Policy is to execute everyone. Chuck Norris never uses a SharePoint Masterpage. ...

“I Saw a Nazi”
... SEE YOU IN A YEAR! 18:28 - Pictures of reconstruction groups: Kacper Gizbo (NowyEkran.pl) pictures of marching of reconstruction groups: masterpage.com.pl ...

Ajax and forms authentication
Forms authentication is nice way to protect your asp.net web pages from unauthorized views. The good thing is that it shields all request for ...

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Startup Pakistan
Pakistan has a whole host of problems. So does every other country in the world. The trouble is that the name Pakistan carries an increasingly ...

Delicious
Keep, share, and discover the best of the Web using Delicious, the world's leading social bookmarking service.

Free Summary Report
Turn on more accessible mode Turn off more accessible mode Skip Ribbon Commands Skip to main content Turn off Animations Turn on Animations Contact ...

Brendan Enrick
Archive - Brendan Enrick

moredotnet
M ore d otnet .NET Interview Questions, ASP.NET, C#, VB.NET, XML, SQL Check Out http://www.dotnetUncle.com √ .NET NOTES OOPS in .NET .NET ...

Using a nested Master Page with ASP.Net
The first thing I actually missed from Webforms are nested masterpages. Fortunately they’re not missing at all, they just figured out those MVC ...

Resources last updated: 2/19/2016 9:04:10 AM