473,508 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to modify <head> tag when using a master page?

I am creating a web app using asp.net 2.0 where all pages are based a
single master page. On some of the aspx pages I need to add javascript
to the head tag in order to use Google maps.

I tried this to access the header:

In the master page:
<HEAD runat="server">

In the aspx page: Page_Load

HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;

i get this error:

"Cannot get inner content of because the contents are not literal"

Is there a way to programatically add to the head tag from within an
aspx page when using master pages?

Dec 4 '05 #1
7 12956
You have to give the head tag an id, and associate it with a declared
CodeBehind HtmlGeneric Control having the same ID.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

<er*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am creating a web app using asp.net 2.0 where all pages are based a
single master page. On some of the aspx pages I need to add javascript
to the head tag in order to use Google maps.

I tried this to access the header:

In the master page:
<HEAD runat="server">

In the aspx page: Page_Load

HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;

i get this error:

"Cannot get inner content of because the contents are not literal"

Is there a way to programatically add to the head tag from within an
aspx page when using master pages?

Dec 4 '05 #2
On 4 Dec 2005 10:21:22 -0800, er*****@gmail.com wrote:

HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;


Header is already a HtmlHead reference, so I can't see how you'd get
the error on this statement.

Are you trying to use the InnerText or InnerHtml properties?

--
Scott
http://www.OdeToCode.com/blogs/scott/
Dec 4 '05 #3
On Sun, 4 Dec 2005 14:57:29 -0500, "Kevin Spencer"
<ke***@DIESPAMMERSDIEtakempis.com> wrote:
You have to give the head tag an id, and associate it with a declared
CodeBehind HtmlGeneric Control having the same ID.


In 2.0 the <head runat="server"> tag is automatically wired to the
Page.Header property.

--
Scott
http://www.OdeToCode.com/blogs/scott/
Dec 4 '05 #4
Sorry, I neglected to mention that the error actually came when
attempting to access the InnerText property.

Dec 5 '05 #5
The easiest way to modiy the <head> then, when using a master page, is
probably to use a ContentPlaceHolder in the head. Provide default
content for the ContentPlaceHolder in the master page.

If the page using that master page wants to override the head content,
it can specify a content control to overwrite what is there.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 5 Dec 2005 09:42:48 -0800, id*****@gmail.com wrote:
Sorry, I neglected to mention that the error actually came when
attempting to access the InnerText property.


Dec 5 '05 #6
Actually, according to the W3C (...bow before them) you HAVE to put
style in the head, but you can put script just about anywhere.

So, don't worry about it...

That said, you could put a literal up in the <head></head> masterpage
area and just access that from the content pages...

((Literal)this.Master.FindControl("litStyles")).Te xt = "<link
rel=\"alternate\" type=\"application/atom+xml\" title=\"WinFX
Harmonics\" href=\"http://www.davidbetz.net/winfx/atom.xml\" />";

Just remember this:
1) Use FindControl
2) Cast it
3) Use it

This technique works in many, MANY places...and is the expert
databinders best friend!

David Betz
http://davidbetz.net/dynamicbliss/
http://davidbetz.net/winfx/

Dec 6 '05 #7

er*****@gmail.com,

did you solved your problem?
I have the same error, and I've tried all the suggestions given in this
thread, but I still cannot access to the head section of the master
page.

I have to add that, while you tried to add some javascripts (and you
could now use the new ClientScript member of the Page class), I have to
add some <style> tags (<link> tag for MS Explorer).

Anybody can help me?

Thank you,
Paolo.
--
BenHur73
------------------------------------------------------------------------
BenHur73's Profile: http://forums.yourdomain.com.au/member.php?userid=28
View this thread: http://forums.yourdomain.com.au/showthread.php?t=17570

Jan 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2130
by: Andrés Giraldo | last post by:
Hi! It's possible to register some script between the <head> and </head> actually I'm Using RegisterStartupScript and RegisterClientBlockScript, but it works on the body By the way... how...
2
2024
by: ryan.mclean | last post by:
Hello everyone. Hope ya'll had a nice New Year. Anyway, my question is why won't this work? I must be doing something dumb . . . here is the code: in the body tag, I have this code (just to...
7
5527
by: Ignac Vucko | last post by:
Is writing a document *during* page load safe and supported for all 4th and 5th generation browsers? If not, can you show me a specific example/browser where it causes problems? <html> <head>...
10
6827
by: Brian W | last post by:
Hi All, I have a web user control that, among other things, provides Print this page, and Email this page functionality I have this script that is to execute on the click of the asp:hyperlinks ...
6
5449
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of...
3
1463
by: Sam Samnah | last post by:
Ok I have a bit of a problem with a Server control I am building. I need to write a client-side Javascript block between the open and closing Head tag. I have tried the following methods: first...
1
4738
by: Frank | last post by:
I would like to create a custom control that generates everything that will be in the <head> </head> section. This would allow me to make changes on all pages withing a site in one location. ...
2
1497
by: walter | last post by:
Hi there, when I use Page.ClientScript.Register...Block() , the script got added within the <form> tag. It's not a big problem, but I still want to put them in the <head> tag. See if you have any...
8
3072
by: deko | last post by:
<head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title>Home Page</title> <!--> <style#navlist a { height: 1em; } </style> <!--> </head> Is the statement above...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.