473,811 Members | 2,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<Head>Tag

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 attempt
Page.Response.A ppendHeader(som eStringBuilder) ;
result:
Returned nothing on the page.

Second attempt
if(!Page.IsStar tupScriptRegist ered("startup") ){

StringBuilder jsLoad=new StringBuilder() ;

jsLoad.Append(@ "Some Javascript");

string CMSCScript=jsLo ad.ToString();

Page.RegisterCl ientScriptBlock ("startup",CMSC Script);

}

Result:

Returned Client Script at the top between the Open and Close <Body> tags.

I need to place the script block between the Open and Close <Head> tags.
Can someone tell me how this is done? By the way, for the above code I
override the PreRender() method.

Can someone please help me with this or lead me to the right web site for a
guide. Thank you.

I am Sam- :-)
Nov 19 '05 #1
3 1478

Here's a guy who wrote a whole article on it :)
http://www.codeproject.com/aspnet/scriptregister.asp

My simple solution would be to give the <head> tag a runat=server attribute
so can manipulate its contents with asp.

Your first solution is a good joke I hope you learned by now ;)

Cheers,
Tom Pester
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 attempt
Page.Response.A ppendHeader(som eStringBuilder) ;
result:
Returned nothing on the page.
Second attempt
if(!Page.IsStar tupScriptRegist ered("startup") ){
StringBuilder jsLoad=new StringBuilder() ;

jsLoad.Append(@ "Some Javascript");

string CMSCScript=jsLo ad.ToString();

Page.RegisterCl ientScriptBlock ("startup",CMSC Script);

}

Result:

Returned Client Script at the top between the Open and Close <Body>
tags.

I need to place the script block between the Open and Close <Head>
tags. Can someone tell me how this is done? By the way, for the above
code I override the PreRender() method.

Can someone please help me with this or lead me to the right web site
for a guide. Thank you.

I am Sam- :-)

Nov 19 '05 #2
asp.net doesn't support this directly.

1) Page.Response.A ppendHeader(), adds a response header , which comes before
any html.
2) Page.RegisterCl ientScriptBlock (), renders the script block (you must
include the script tags), right after the <form>
3) Page.RegisterSt artupScript, renders the script block right before the
</form>

if you want to add code in the header, you need to add a runat on the
header. then using the HtmlGeneric control you can create script blocks. or
you can get the innerHtml from the header, and insert the script blcks
directly.
<header id="myHeader" runat=server>
</header>

-- bruce (sqlwork.com)
"Sam Samnah" <we**********@t erraquest123.ca > wrote in message
news:Oe******** ******@TK2MSFTN GP10.phx.gbl...
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 attempt
Page.Response.A ppendHeader(som eStringBuilder) ;
result:
Returned nothing on the page.

Second attempt
if(!Page.IsStar tupScriptRegist ered("startup") ){

StringBuilder jsLoad=new StringBuilder() ;

jsLoad.Append(@ "Some Javascript");

string CMSCScript=jsLo ad.ToString();

Page.RegisterCl ientScriptBlock ("startup",CMSC Script);

}

Result:

Returned Client Script at the top between the Open and Close <Body> tags.

I need to place the script block between the Open and Close <Head> tags.
Can someone tell me how this is done? By the way, for the above code I
override the PreRender() method.

Can someone please help me with this or lead me to the right web site for
a guide. Thank you.

I am Sam- :-)

Nov 19 '05 #3
Thanx Bruce for replying.

I need to be able to place the client script directly from the custom server
control I'm building. How can I set the containing page head tag directly
from my server control to Runat="server" if I can't access the Head tag
element from my control to begin with?

"Bruce Barker" <br************ ******@safeco.c om> wrote in message
news:e%******** ********@tk2msf tngp13.phx.gbl. ..
asp.net doesn't support this directly.

1) Page.Response.A ppendHeader(), adds a response header , which comes
before any html.
2) Page.RegisterCl ientScriptBlock (), renders the script block (you must
include the script tags), right after the <form>
3) Page.RegisterSt artupScript, renders the script block right before the
</form>

if you want to add code in the header, you need to add a runat on the
header. then using the HtmlGeneric control you can create script blocks.
or you can get the innerHtml from the header, and insert the script blcks
directly.
<header id="myHeader" runat=server>
</header>

-- bruce (sqlwork.com)
"Sam Samnah" <we**********@t erraquest123.ca > wrote in message
news:Oe******** ******@TK2MSFTN GP10.phx.gbl...
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 attempt
Page.Response.A ppendHeader(som eStringBuilder) ;
result:
Returned nothing on the page.

Second attempt
if(!Page.IsStar tupScriptRegist ered("startup") ){

StringBuilder jsLoad=new StringBuilder() ;

jsLoad.Append(@ "Some Javascript");

string CMSCScript=jsLo ad.ToString();

Page.RegisterCl ientScriptBlock ("startup",CMSC Script);

}

Result:

Returned Client Script at the top between the Open and Close <Body> tags.

I need to place the script block between the Open and Close <Head> tags.
Can someone tell me how this is done? By the way, for the above code I
override the PreRender() method.

Can someone please help me with this or lead me to the right web site for
a guide. Thank you.

I am Sam- :-)


Nov 19 '05 #4

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

Similar topics

7
5566
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> <script>document.writeln("<div id='mydiv'>stuff</div>");</script> </head> <body>blah</body>
6
5473
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 the page dynamically when the page is rendered? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
2
1885
by: Dave | last post by:
I'm inheriting from a custom page class instead of System.Web.UI.Page, and I want to add a .css or .js link to the page's <head> tag. Can this be done? I tried this using but it just adds it to the bottom of the page....I need to somehow reference the <head> server-side? HtmlGenericControl link = new HtmlGenericControl("LINK"); link.Attributes.Add("rel","stylesheet"); link.Attributes.Add("type","text/css");...
1
393
by: MBO | last post by:
Hello NG, I'm writing a control that needs to put a clientside javascript between the <HEAD> Tags of a webpage where it is placed on. I've seen from other threads in this NG, that one solution is to assign a runat="server" and an id="myheader" attribute to the HEAD-Tag. On the code behind I've defined a variable Protected myHeader As System.Web.UI.HtmlControls.HtmlGenericControl to access the HEAD tag. My Problem is, that everytime...
3
4264
by: thomasamillergoogle | last post by:
Is it possible that my user control can add code to the HEAD of the parent page that hosts the control?
7
12978
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 this to access the header: In the master page: <HEAD runat="server"> In the aspx page: Page_Load
5
2504
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 the dynamically assigned <base href='??'> and <META NAME="Description" CONTENT="??"> Is there a work around?
2
1507
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 suggestion. Thanks.
3
1457
by: phpmel | last post by:
Hi guys, I have yet another question. I am working with this html form that uses a template. <head> //is greyed out //some greyed out <style >stuff is next <!-- InstanceEndEditable -->//greyed out </head>//greyed out <body>//greyed out
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.