Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

Reply
Thread Tools

Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

 
 
Sergey Morkovkin
Guest
Posts: n/a
 
      09-11-2003
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
 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      09-11-2003
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Anatoly
Guest
Posts: n/a
 
      09-11-2003
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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



 
Reply With Quote
 
Ezra Epstein
Guest
Posts: n/a
 
      09-13-2003
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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



 
Reply With Quote
 
Slava Tihonyuk
Guest
Posts: n/a
 
      09-15-2003
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY Sergey Morkovkin ASP .Net 5 07-14-2009 04:50 PM
Problems creating head section - Unrecognized tag prefix or device filter 'asp' Luurs ASP .Net 1 08-08-2006 10:20 PM
Reading HEAD section META tag (name / content). Rick ASP .Net 3 05-10-2006 04:49 PM
Write into <HEAD></HEAD> section? Jiho Han ASP .Net Building Controls 6 01-16-2004 04:31 PM
Injecting code into the <head></head> section Brian W ASP .Net 10 07-02-2003 07:53 PM



Advertisments