473,473 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Controls in the <head> section

I need literal controls in the <head> section of my page. I need to be able
to load dynamic values in the head section. It works fine in ASP.Net 1.1, but
Asp.net 2.0 gives a compile error.
I need the dynamically assigned <base href='??'> and
<META NAME="Description" CONTENT="??">
Is there a work around?
Jan 10 '06 #1
5 2478
Not sure, but check the Page.Header class, it has a bunch of useful
functionality, including the ability to add controls do it,
Page.Header.Controls.Add(...)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Arne" <Ar**@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
I need literal controls in the <head> section of my page. I need to be able
to load dynamic values in the head section. It works fine in ASP.Net 1.1,
but
Asp.net 2.0 gives a compile error.
I need the dynamically assigned <base href='??'> and
<META NAME="Description" CONTENT="??">
Is there a work around?

Jan 10 '06 #2
Just off the top of my head (which works), in Page_Load:

StringBuilder sb = new StringBuilder();
string someName = "keywords";
string someKeywords = "blah, doh";
sb.Append("<meta name=\"");
sb.Append(someName);
sb.Append("\" content=\"");
sb.Append(someKeywords);
sb.Append("\" />");
Header.Controls.Add(new LiteralControl(sb.ToString()));

Not sure this is how I would handle it, but it is a temporary solution. Wrap
it in its own function so you can change the implementation if you find a
better way.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Arne" wrote:
I need literal controls in the <head> section of my page. I need to be able
to load dynamic values in the head section. It works fine in ASP.Net 1.1, but
Asp.net 2.0 gives a compile error.
I need the dynamically assigned <base href='??'> and
<META NAME="Description" CONTENT="??">
Is there a work around?

Jan 10 '06 #3
I have tried that, but header has a value of nothing in the page_load and
prerender events.

"Cowboy (Gregory A. Beamer) - MVP" wrote:
Just off the top of my head (which works), in Page_Load:

StringBuilder sb = new StringBuilder();
string someName = "keywords";
string someKeywords = "blah, doh";
sb.Append("<meta name=\"");
sb.Append(someName);
sb.Append("\" content=\"");
sb.Append(someKeywords);
sb.Append("\" />");
Header.Controls.Add(new LiteralControl(sb.ToString()));

Not sure this is how I would handle it, but it is a temporary solution. Wrap
it in its own function so you can change the implementation if you find a
better way.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Arne" wrote:
I need literal controls in the <head> section of my page. I need to be able
to load dynamic values in the head section. It works fine in ASP.Net 1.1, but
Asp.net 2.0 gives a compile error.
I need the dynamically assigned <base href='??'> and
<META NAME="Description" CONTENT="??">
Is there a work around?

Jan 10 '06 #4
Hi Arne,

the header has a value of null because inside the ASPX, there is no
'runat=server' attribute present on the <head> tag.
Try this:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected override void OnLoad(EventArgs e)
{
HtmlMeta meta = new HtmlMeta();
meta.Name = "Description";
meta.Content = "SomeRandomValue";
Header.Controls.Add(meta);
base.OnLoad(e);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

Grtz,

Wouter van Vugt
Trainer - Info Support
http://blogs.infosupport.com/wouterv

Jan 10 '06 #5
You can also turn add the meta tags on the form and set runat="server", e.g.

<head>
<meta name="Description" runat="server" id="meta1"/>
<base runat="server" id="base1"/>
</head>

then in the codebehind you would access them directly like this:

meta1.Content = "My Site description";
base1.Attributes.Add("href","http://www.website.com");
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Arne" wrote:
I need literal controls in the <head> section of my page. I need to be able
to load dynamic values in the head section. It works fine in ASP.Net 1.1, but
Asp.net 2.0 gives a compile error.
I need the dynamically assigned <base href='??'> and
<META NAME="Description" CONTENT="??">
Is there a work around?

Jan 10 '06 #6

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

Similar topics

2
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
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
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
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
by: jsh02_nova | last post by:
Anybody know how to add a script block to the html <head> section programmatically without using the 'RegisterScriptBlock' functions? -- thx -jsh
3
by: PJ6 | last post by:
I want to render this text into the <HEAD> section of a page (and perhaps mute any existing title declaration, or alter it to be this instead) - <title runat="server" id=HtmlTitle></title> It...
7
by: ericgla | last post by:
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...
1
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
by: Rex | last post by:
I am writing a script that executes a bunch of queries through a form on a website and reads the results. I am only interested in the <titlesection in the <headof each web page. Currently, each...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.