473,372 Members | 1,018 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,372 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 4718
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.