473,404 Members | 2,114 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,404 software developers and data experts.

Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

Hi, guys!
Does anyone knows the resolution of a problem when i need to insert <link> or <script> tag into HEAD section dynamically?
I was trying few ways to do this: 1) RegisterClientScriptBlock inserts script right after form.
2) RegisterStartupScript inserts script before post form.
3) Page.Controls.Add(new LiteralControl("<LINK rel='stylesheet' href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works, but inserts only the last one tag to the end of a page.

P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src attribute of an existing tag.

--
Sergey Morkovkin, Web Project Leader
Celline Ltd. - World of content in real time
http://www.celline.com.ua
+380 44 234 65 36
+380 67 280 11 22
Nov 17 '05 #1
4 9207
I tried this:
Add manually into aspx file id attribute to HEAD tag "myHead", add also
runat=server attribute.
in code behind add line inside WebForm:

protected System.Web.UI.HtmlControls.HtmlGenericControl myHead;

When You can write on Page_Load:
myHead.innerHtml += [anything you want to add in HEAD]

HTH
"Sergey Morkovkin" <se****@celline.com.ua> wrote in message
news:op**************@news.lucky.net...
Hi, guys!
Does anyone knows the resolution of a problem when i need to insert <link> or <script> tag into HEAD section dynamically? I was trying few ways to do this: 1) RegisterClientScriptBlock inserts script right after form. 2) RegisterStartupScript inserts script before post form.
3) Page.Controls.Add(new LiteralControl("<LINK rel='stylesheet' href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
but inserts only the last one tag to the end of a page.
P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src attribute of an existing tag.
--
Sergey Morkovkin, Web Project Leader
Celline Ltd. - World of content in real time
http://www.celline.com.ua
+380 44 234 65 36
+380 67 280 11 22

Nov 17 '05 #2
Add a "runat=server" attribute to your <head> tag, give it an id, and wire
it up to an HtmlGenericControl object in your CodeBehind. Then you can
manipulate it like any other Control, as well as adding to its' Controls
Collection.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Sergey Morkovkin" <se****@celline.com.ua> wrote in message
news:op**************@news.lucky.net...
Hi, guys!
Does anyone knows the resolution of a problem when i need to insert <link> or <script> tag into HEAD section dynamically? I was trying few ways to do this: 1) RegisterClientScriptBlock inserts script right after form. 2) RegisterStartupScript inserts script before post form.
3) Page.Controls.Add(new LiteralControl("<LINK rel='stylesheet' href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
but inserts only the last one tag to the end of a page.
P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src attribute of an existing tag.
--
Sergey Morkovkin, Web Project Leader
Celline Ltd. - World of content in real time
http://www.celline.com.ua
+380 44 234 65 36
+380 67 280 11 22

Nov 17 '05 #3
Another easy way if you're just looking to change the href of a LINK tag is:

<LINK rel="stylesheet" type="text/css" href="<%= MyDynamicLink %> ">

It's a bit of a hybrid approach: using ASP's <%= %> in an ASP.NET page.

In the code-behind you'd have

C#: <snip>
public string MyDynamicLink
{
get { return "style.css" ); } // your variable goes here instead of
the literal "style.css"
}
</snip>

Ezra E.

"Sergey Morkovkin" <se****@celline.com.ua> wrote in message
news:op**************@news.lucky.net...
Hi, guys!
Does anyone knows the resolution of a problem when i need to insert <link> or <script> tag into HEAD section dynamically? I was trying few ways to do this: 1) RegisterClientScriptBlock inserts script right after form. 2) RegisterStartupScript inserts script before post form.
3) Page.Controls.Add(new LiteralControl("<LINK rel='stylesheet' href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
but inserts only the last one tag to the end of a page.
P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src attribute of an existing tag.
--
Sergey Morkovkin, Web Project Leader
Celline Ltd. - World of content in real time
http://www.celline.com.ua
+380 44 234 65 36
+380 67 280 11 22

Nov 17 '05 #4
Hi Sergey

Maybe you can add this
HtmlGenericControl head = (HtmlGenericControl)FindControl("TheHead");

head.Controls.Add(new LiteralControl("<LINK rel='stylesheet'
href='include/inputbox.css' type='text/css'>"));

:)

I tried to program title tag this way too:)

Slava

"Sergey Morkovkin" <se****@celline.com.ua> wrote in message
news:op**************@news.lucky.net...
Hi, guys!
Does anyone knows the resolution of a problem when i need to insert <link> or <script> tag into HEAD section dynamically? I was trying few ways to do this: 1) RegisterClientScriptBlock inserts script right after form. 2) RegisterStartupScript inserts script before post form.
3) Page.Controls.Add(new LiteralControl("<LINK rel='stylesheet' href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
but inserts only the last one tag to the end of a page.
P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src attribute of an existing tag.
--
Sergey Morkovkin, Web Project Leader
Celline Ltd. - World of content in real time
http://www.celline.com.ua
+380 44 234 65 36
+380 67 280 11 22

Nov 17 '05 #5

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

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
1
by: Mike Blackett | last post by:
Hi all, I have several folders of images. Inside each folder is a JS file defining an array of the images with a description of each image. When a user selects a 'gallery'/folder on my site,...
14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
2
by: Brian | last post by:
Hi all. I have a bunch of pages that reference an external script from the head section. I'd like to add additional <script> elements to the pages' bodies, but I can't edit the pages...
4
by: MPennig | last post by:
Here's my situation. I have a function defined in my document's <head> section which adds a <script> tag to a specified <div> tag. The added <script> has a src="" attribute pointing to a PHP file,...
4
by: Sergio del Amo | last post by:
i, I have the next html page <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a...
2
by: Jeffrey T. | last post by:
I had some JavaScript functions defined in the <SCRIPT> section at the top of an aspx page (tested fine there). I then moved the JavaScript functions to their own separate file and then...
2
by: hb | last post by:
Hi, I need to assign javascript code dynamically to this tag in <head> section. Would you please tell me how to use <script> tag in code behind? Thank you hb
28
by: Giggle Girl | last post by:
Can someone show me how to insert a row at any given row index of an already created table? It only has to work in IE6 (used on intranet at work). Specifically, if a table is 20 rows in total...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...
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,...
0
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...

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.