Solved

Using Master Page and the page.header is showing up as nothing

Posted on 2008-06-12
5
787 Views
Last Modified: 2013-11-07
I have a simple master page, nothing too fancy in there, and have a content page that inheirts from a page base class. Reason for the base class is to move the view state down to the bottom of the page. All that seems to work the way I want, so no issue there.

Issue comes when I am trying to setup a routine where I can call from any page and add metadata to my page rendered. In my page base class I have a method called AddPAgeMetaData and the code is attached. In the page load event of the content page I have the following piece of code.

  AddPageMetaData("keywords", "some key words", Page.Header)
        AddPageMetaData("description", "some description", Page.Header)

Page.Header is always nothing and I am not sure why that is the case, because I could have sworn when playing around with this on my laptop at home, I was able to get this working. I have tried to do this a number ways, as in taking out the call to the page base class, but still get the same result. If anyone has any ideas on what is going on here, please let me know.

In the function call you may notic swuh, this is simple the following at the top of the page base class:
Imports swuh = System.Web.UI.HtmlControls





Public Function AddPageMetaData(ByVal strKeyName As String, ByVal strKeyValue As String, ByVal pgHeader As swuh.HtmlHead) As Boolean
        'Local variables
        Dim blnReturn As Boolean = True
        Dim pgMetaData As New swuh.HtmlMeta
        Dim ltrNewLine As New Literal
 
        'Local constants
        Const cstrPROC_FUNC_NAME As String = _cstrMODULE_NAME & ".AddPageMetaData"
 
        Try
 
            With ltrNewLine
                .Text = Environment.NewLine
            End With
 
            With pgMetaData
                .Name = strKeyName
                .Content = strKeyValue
            End With
 
            'Create the meta data value
            With pgHeader
                .Controls.Add(pgMetaData)
                .Controls.Add(ltrNewLine)
            End With
        Catch ex As Exception
        Finally
            pgMetaData = Nothing
            ltrNewLine = Nothing
 
        End Try
 
    End Function

Open in new window

0
Comment
Question by:JDEE8297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Expert Comment

by:skiltz
ID: 21768356
can you not just put a content placer holder in the head section of the masterpage and then use that content holder in the child page?
0
 

Author Comment

by:JDEE8297
ID: 21771616
Would love to do that, but I am afraid there will be other meta tags besides the normal two, so I was trying to make it smart enough to handle all of these.
0
 

Author Comment

by:JDEE8297
ID: 21777689
This is why I sometimes I really dislike programming? same piece of code on my laptop at home works every single time I run it, page.header always has a value and I have no idea when running this on my machine at work it doesn't have any value.

Same code just different computers.

On the page base class I have this at the top of the page
  Inherits System.Web.UI.Page

Inside the content page I reference the base class like so
Inherits cPages

I set the call at the form load
AddPageMetaData("keywords", "Some keywords", Page.Header)
            AddPageMetaData("description", "some description", Page.Header)
            AddPageMetaData("bollox", "something else", Page.Header)

And everytime Page.Header is a big fat nothing, and yet on my vista laptop it is not nothing. Finally, something on Vista works that doesn't work on xp ;). :)
0
 

Accepted Solution

by:
JDEE8297 earned 0 total points
ID: 21777768
figured it out, was missing the attribute runat="server" in the head tag.

http://www.joshsalwen.com/CategoryView,category,ASP.NET%202.0.aspx

0
 

Expert Comment

by:Merion
ID: 25200017
I could not figure out  why it was nothing always.
Thanks this was really helpful.
 

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Format Transaction Number 19 50
PowerShell: Adding ToGB to a script 4 75
Need a quick overview of Selenium testing 2 36
.NET universe documentation poster 2 25
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question