471,086 Members | 1,137 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 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 4543
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Arne | last post: by

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.