473,772 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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) RegisterClientS criptBlock inserts script right after form.
2) RegisterStartup Script inserts script before post form.
3) Page.Controls.A dd(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 9245
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.H tmlControls.Htm lGenericControl myHead;

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

HTH
"Sergey Morkovkin" <se****@celline .com.ua> wrote in message
news:op******** ******@news.luc ky.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) RegisterClientS criptBlock inserts script right after form. 2) RegisterStartup Script inserts script before post form.
3) Page.Controls.A dd(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=serv er" attribute to your <head> tag, give it an id, and wire
it up to an HtmlGenericCont rol 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.luc ky.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) RegisterClientS criptBlock inserts script right after form. 2) RegisterStartup Script inserts script before post form.
3) Page.Controls.A dd(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.luc ky.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) RegisterClientS criptBlock inserts script right after form. 2) RegisterStartup Script inserts script before post form.
3) Page.Controls.A dd(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
HtmlGenericCont rol head = (HtmlGenericCon trol)FindContro l("TheHead");

head.Controls.A dd(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.luc ky.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) RegisterClientS criptBlock inserts script right after form. 2) RegisterStartup Script inserts script before post form.
3) Page.Controls.A dd(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
8729
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, returned the hyperlinked page title, filename, and the body txt (30 preceding and following words) in context with the search word highlighted. Excellent.! See it working at: http://www.ipt.co.za Just search for "firearm"
1
3285
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, I want to be able to load in this JS file and create the HTML page of the images and descriptions. Before you say "use a database...", I can't due to the hosting company.
14
2620
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 (that part's not here -- spotlighting the problem code): --------BEGIN CODE PAGE------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
9093
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 themselves. I'd like to add them from the existing script, but I need to make sure that the elements get added to the end of the document's body section. Using document.write("<script ..."); the elements get added to the head section! I'm trying to use...
4
2261
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, which dynamically returns JavaScript. In Safari, the src file isn't downloaded. Neither is any code contained within the new script tag . In IE(6) and Firefox, this works as expected. Here's my code. I hope it will better illustrate what I'm...
4
6318
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 href=\"fadfaf\">anchor</a>blalbababa</span>"
2
1553
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 referenced that file in the <HEAD> section of the aspx page. I then removed the <SCRIPT> section from the aspx page, and the JavaScript stopped working (it was getting called, but some functionality wasn't working). I verified the path and file name to...
2
2503
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
18538
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 (thought his will vary), and someone wants to insert a new row at row 5, i need for one row to be added, and each of the rows from 5-20 to be "cloned" to 6-21. The contents of row 5 may vary as well; it is not a straight copy of an exisiting row.
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
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
5354
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
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.