473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can I Use HTML Text Writer i a Custom Control to Render the <head> Section?

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.

But can I do so since the control would not be withing a <form> tag in the
aspx page?

Can I do like so?:

<%@ Page language="c#" Codebehind="contests.aspx.cs" AutoEventWireup="false"
Inherits="MZ.contests" %>
<%@Register TagPrefix="mz" Tagname="HeadSection"
Src="mzControls/HeadSection.ascx" %>

<mz:HeadSection runat="server" />

<body>
..
..
..
..
</body>
And in the custom control:

using System;

using System.Web;

using System.Web.UI;

namespace myControls

{

public class ShowHeadSection: Control

{

protected override void Render( HtmlTextWriter objTextWriter )

{

objTextWriter.RenderBeginTag( "Head" );

objTextWriter.RenderBeginTag(
"Title" );objTextWriter.Write( "Title");objTextWriter.RenderEndTag();

objTextWriter.RenderBeginTag( "meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" );objTextWriter.RenderEndTag();

objTextWriter.RenderBeginTag( "LINK
href="/common/css/stylesheet.css" type="text/css"
rel="stylesheet");objTextWriter.RenderEndTag();

objTextWriter.RenderBeginTag( "script language="JavaScript"
src="common/js/global.js"
type="text/JavaScript" );objTextWriter.RenderEndTag();

objTextWriter.RenderEndTag();

}

}

}

NOTICE, I am also trying to render a meta tag, a link tag, and a script tag

Thanks in advance for any help ( Peter :o) )

Frank K.


Jan 18 '06 #1
1 4715
Frank,

Are you using ASP.NET 2.0 (.NET 2.0)? If so, you can use master pages
which will act as a template for all of your pages, which you can declare
the information in the head section of the returned HTML.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank" <fk******@pfmail.com> wrote in message
news:uE**************@tk2msftngp13.phx.gbl...
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.

But can I do so since the control would not be withing a <form> tag in the
aspx page?

Can I do like so?:

<%@ Page language="c#" Codebehind="contests.aspx.cs"
AutoEventWireup="false" Inherits="MZ.contests" %>
<%@Register TagPrefix="mz" Tagname="HeadSection"
Src="mzControls/HeadSection.ascx" %>

<mz:HeadSection runat="server" />

<body>
.
.
.
.
</body>
And in the custom control:

using System;

using System.Web;

using System.Web.UI;

namespace myControls

{

public class ShowHeadSection: Control

{

protected override void Render( HtmlTextWriter objTextWriter )

{

objTextWriter.RenderBeginTag( "Head" );

objTextWriter.RenderBeginTag(
"Title" );objTextWriter.Write( "Title");objTextWriter.RenderEndTag();

objTextWriter.RenderBeginTag( "meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" );objTextWriter.RenderEndTag();

objTextWriter.RenderBeginTag( "LINK
href="/common/css/stylesheet.css" type="text/css"
rel="stylesheet");objTextWriter.RenderEndTag();

objTextWriter.RenderBeginTag( "script language="JavaScript"
src="common/js/global.js"
type="text/JavaScript" );objTextWriter.RenderEndTag();

objTextWriter.RenderEndTag();

}

}

}

NOTICE, I am also trying to render a meta tag, a link tag, and a script
tag

Thanks in advance for any help ( Peter :o) )

Frank K.

Jan 18 '06 #2

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>...
5
by: Arne | last post by:
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...
2
by: Frank | last post by:
From: "Frank" <fkaesser@pfmail.com> Subject: Can I Use HTML Text Writer i a Custom Control to Render the <head> Section? Date: Wednesday, January 18, 2006 11:38 AM I would like to create a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.