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

R

Rolf Welskes

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
 
C

clintonG

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
 
D

dingsheng

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"
%>
 
S

Steven Cheng[MSFT]

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.
 
R

Rolf Welskes

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
 
S

Steven Cheng[MSFT]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top