Using themed css files requires a header control on the page

S

samuelberthelot

Hi,
I get this exception when I use a themed css file. In my web.config
file I have:
<pages theme="dRise">

and the trouble page is a master page :

<% Response.Write(Header)%>
<form id="form1" runat="server">
<div class="FormContent">
<asp:contentplaceholder id="ReportWizard" runat="server">
</asp:contentplaceholder>
</div>
</form>
<% Response.Write(Footer)%>

Header is a property returning :
"<html><head runat=""server""></head><body>"
and Footer returns:
"</body></html>"

The above code WORKS if I link the css file directely in the
masterpage, but if I use the themed css it generates the exception .
Can you help ?
thanks
 
G

Guest

Sam,
First off your thinking is right on the money. But your masterpage should
look something like this. More later.

<head runat="server">
<title>Sam's Master Page</title>
</head>
<body class="body">
<form id="form1" runat="server">
<div>

The exception was caused by the response.write This writes directly to the
client browser so <head runat="server"> was sent directly to the client web
browser. ASP.Net could not find the head element (it was sent to client web
browser) and threw an exception "no head element to put your css theme link
in"

Also Sam please start using a code behind or <script runat="server"> script
blocks for your coding. <% %> style coding is obsolete.

Good Luck
DWS
 
S

samuelberthelot

Thanks for replying.
I actually do use code-behind, except in this one off circumpstance
where I've used <% %>. But this is not the problem, isn't it ?

I understood your explanations, but does this mean I can't write the
page dynamically when using a theme ?
 
A

Alan Silver

Thanks for replying.
I actually do use code-behind, except in this one off circumpstance
where I've used <% %>. But this is not the problem, isn't it ?

Yes, it's exactly the problem.
I understood your explanations, but does this mean I can't write the
page dynamically when using a theme ?

No, it means that what you write dynamically gets sent to the browser
without the ASP.NET engine doing anything with it. Your problem is that
you need a <head> tag with a runat="server" attribute in a place where
the ASP.NET engine will see it.

Why are you using the Response.Write to write out a bit of static HTML?
This should go in the master file, that's what they are there for. DWS'
point was that the <% %> style of coding is a classic ASP one that has
basically no place in ASP.NET. If you add the <head runat="Server"> to
your master file, then your theme will work fine.

Hope this helps.
 
S

samuelberthelot

of course it would worked if I added <head runat="server"> directely
in the page ! But I can't do it this way.
all the html markups from my project are coming from a database (from
<html> to <body>, including <head runat=server>)
therefore I have to use response.write to write this html dynamically
before the rest of the page.

Is this clear ?
Do you understand my probleme now ?
 
A

Alan Silver

of course it would worked if I added <head runat="server"> directely
in the page ! But I can't do it this way.
all the html markups from my project are coming from a database (from
<html> to <body>, including <head runat=server>)
therefore I have to use response.write to write this html dynamically
before the rest of the page.

You don't *have* to use Response.Write, see below.
Is this clear ?

It's clear, but it's going to cause you a big problem. To apply themes,
the ASP.NET engine needs to be able to parse the <head> tag of your
document at run time. If you are pulling this tag out of a database,
then it's not going to be available at run time, so you can't apply
theme.
Do you understand my probleme now ?

I do, do you understand now why it isn't working?

It sounds like you might need to rethink the way your data is stored.
Wouldn't you be better storing key information in the database and using
that as data for the tags, rather than storing the tags themselves?

For example, if you wanted to store a title for the page, instead of
saving the following in your database...

<head>
<title>my page</title>
</head>

you would be better storing just the text of the title ("my page" in
this case) and have server-side code like this...

<head>
<title><asp:Literal ID="litTitle" runat="server" /></title>
</head>

Then your page could extract the title from the database, and just set
the Text property of the literal to it. That sounds like a more sensible
system anyway, and would allow you to add the runat="server" attribute
to your <head> tag, allowing you to use themes.

Hope this helps
 

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