Master-Content in Asp.net - How to set individual Head for each content page

Discussion in 'ASP .Net' started by Rolf Welskes, Aug 21, 2006.

  1. Rolf Welskes

    Rolf Welskes Guest

    Hello,
    Master-Content in asp.net is very powerful.
    But:
    I have the following:
    One Master-Form.
    30 Content-Forms which are the webpages used.
    Each of this content-forms must have own html-Head-informations.
    Example
    Master:
    <head>
    ..... for alle content pages
    </head>

    ContentPage01
    <head>
    ..... from master
    individual for this page, for example:
    javascript includes
    meta-tags
    css-style-sheets
    </head>

    ContentPage02
    <head>
    ..... from master
    individual for this page, for example:
    javascript includes
    meta-tags
    css-style-sheets
    </head>

    etc.

    So what to do.
    It is not possible to have <head>.... </head> in content-pages.
    It is not possible to put all in the <head></head> in the master
    because is different for each page.

    So, what to do?
    Thank you for any help.
    Rolf Welskes
    Rolf Welskes, Aug 21, 2006
    #1
    1. Advertising

  2. Rolf Welskes

    Mark Rae Guest

    "Rolf Welskes" <> wrote in message
    news:...

    > So, what to do?


    In the Page_Load of the content pages:

    protected void Page_Load(object sender, EventArgs e)
    {
    Header.Title = "Whatever you like";
    }
    Mark Rae, Aug 21, 2006
    #2
    1. Advertising

  3. Rolf Welskes

    clintonG Guest

    Check out the System.Web.UI.HtmlControls namespace [1] and study the
    HtmlHead, HtmlMeta, HtmlLink classes and so on.

    The challenge is how and what to code to the header for various content
    pages. You'll have to start using a base class all content pages inherit
    from. From the Page_PreInit handler of the base class your code will invoke
    another class with methods that can determine which content page is about to
    be used and subsequently which classes from the HtmlControls namespace are
    to be used given the circumstantial requirements for that specific content
    page.

    Clear as mud?

    <%= Clinton Gallagher
    NET csgallagher AT metromilwaukee.com
    URL http://clintongallagher.metromilwaukee.com/
    MAP 43°2'17"N 88°2'37"W : 43°2'17"N 88°2'37"W

    [1] http://msdn2.microsoft.com/en-us/library/system.web.ui.htmlcontrols.aspx


    "Mark Rae" <> wrote in message
    news:etB$...
    > "Rolf Welskes" <> wrote in message
    > news:...
    >
    >> So, what to do?

    >
    > In the Page_Load of the content pages:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > Header.Title = "Whatever you like";
    > }
    >
    clintonG, Aug 21, 2006
    #3
  4. Rolf Welskes

    dingsheng Guest

    the @Page directive in content page has a attribute "title", so you can
    modify it to meet your requirememt,e.g.,
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="XXX"
    %>
    dingsheng, Aug 22, 2006
    #4
  5. Hello Rolf,

    For your scenario, do you think it possible and doable that we use code to
    programmatically create and add html items into the <header> sections of
    content page? If so, you can consider dynamically creating those html
    header items (as Clinton has mentioned) and add them into your content
    page's Header. .e.g.

    ===================================
    protected void Page_Load(object sender, EventArgs e)
    {
    // modify existing <meta> defined in master page
    HtmlMeta meta = Page.Header.FindControl("metaRedirect") as HtmlMeta;

    meta.Content = "";// "2;URL=http://msdn2.microsoft.com/";

    // adding new elements into content page's header

    HtmlLink link = new HtmlLink();
    link.Href = "~/styles/default.css";
    link.Attributes["rel"] = "stylesheet";

    Page.Header.Controls.Add(link);


    HtmlGenericControl script = new HtmlGenericControl("script");
    script.Attributes["src"] = Page.ResolveUrl("~/scripts/default.js");

    Page.Header.Controls.Add(script);

    ..................
    }

    ==================================

    Hope this helps.


    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Aug 22, 2006
    #5
  6. Rolf Welskes

    Rolf Welskes Guest

    Hello,
    thank you for the comments, I think it will help to solve the problem.

    BUT:
    All is done in program code.

    Hint for Microsoft:

    It would be very easy to have a head-tag
    <head>.... </head> also in the content pages and when merging content and
    master,
    simple the head information of the content is append in the master.

    This would be more simple, because I could code in html and not to write
    program code
    that generates html.

    Thank you again.
    Rolf Welskes
    Rolf Welskes, Aug 22, 2006
    #6
  7. Rolf Welskes

    Mark Rae Guest

    "Rolf Welskes" <> wrote in message
    news:%...

    > This would be more simple, because I could code in html and not to write
    > program code that generates html.


    Do you have a problem writing code...?
    Mark Rae, Aug 22, 2006
    #7
  8. Thanks for your quick reply Rolf,

    Though I'm not sure whether this is already added into the plan of next
    version of ASPNET, it is really a good ideas to submit this request on our
    feedback center:

    #Visual Studio and .NET Framework Feedback
    http://connect.microsoft.com/feedback/default.aspx?SiteID=210

    Also, you can vote any other existing feedback there so that the product
    team can get more comments and consider the update plan on the products.

    Thanks again for your posting and feedback.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Aug 22, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian W
    Replies:
    10
    Views:
    757
    Brian W
    Jul 2, 2003
  2. showme

    PHP and ASP.NET go HEAD to HEAD

    showme, Jul 8, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    711
    Sherif ElMetainy
    Jul 10, 2004
  3. Karl
    Replies:
    0
    Views:
    386
  4. Lloyd Dupont
    Replies:
    2
    Views:
    2,948
    Lloyd Dupont
    Sep 22, 2004
  5. Jiho Han

    Write into <HEAD></HEAD> section?

    Jiho Han, Jan 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    223
    Sam Fields
    Jan 16, 2004
Loading...

Share This Page