Page.Title is blank in MasterPage after setting in ASPX page
by johna | June 8, 2016 | ASP.NET Web Forms Web Development
I came across an issue where I was setting Page.Title in my ASPX page's Page_Load event, but it was appearing blank when I was attempting to retrieve the value in the MasterPage's Page_PreRender event.
Thanks to a comment on this blog post, I found the solution.
Here's what the anonymous comment said:
So the solution is to use the following instead of Page.Title:
Thanks to a comment on this blog post, I found the solution.
Here's what the anonymous comment said:
I ran into this problem as well. Looked in Reflector and figured out why. Seems like this is a bug to me. On the setter, if the page has a Header control, then setting the Title property actually changes Header.Title, but if the _titleToBeSet property already has a value (mine does because I'm using localized resources) then it doesn't clear out the old value and the getter still returns _titleToBeSet instead of Header.Title.
So I just changed my code to return this:
return (Page.Header != null ? Page.Header.Title : null) ?? Page.Title;
So the solution is to use the following instead of Page.Title:
(Page.Header != null ? Page.Header.Title : null) ?? Page.Title;
Related Posts
Converting dBase IV programs to run in the browser
by johna | September 13, 2024
Some pointless entertainment trying to get some old dBase programs running in the browser.
How to set up a debugging using the Turnkey Linux LAMP stack and VS Code
by johna | December 19, 2023
The second part in my guide to setting up a website and database using the Turnkey Linux LAMP stack.
How to set up a website and database using the Turnkey Linux LAMP stack
by johna | November 18, 2023
If you need to host your own website for the purposes of web development, Turnkey Linux LAMP Stack is an easy to install all-in-one solution that you can set up on a spare computer or a VM (Virtual Machine).
Comments
There are no comments yet. Be the first to leave a comment!