Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sergey Morkovkin

    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

    +380 44 234 65 36
    +380 67 280 11 22
  • Anatoly

    #2
    Re: Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

    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" <sergey@celline .com.ua> wrote in message
    news:oprvb2m9tk 80s4pa@news.luc ky.net...[color=blue]
    > Hi, guys!
    > Does anyone knows the resolution of a problem when i need to insert <link>[/color]
    or <script> tag into HEAD section dynamically?[color=blue]
    > I was trying few ways to do this: 1) RegisterClientS criptBlock inserts[/color]
    script right after form.[color=blue]
    > 2) RegisterStartup Script inserts script before post form.
    > 3) Page.Controls.A dd(new LiteralControl( "<LINK rel='stylesheet '[/color]
    href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
    but inserts only the last one tag to the end of a page.[color=blue]
    >
    > P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src[/color]
    attribute of an existing tag.[color=blue]
    >
    > --
    > 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[/color]


    Comment

    • Kevin Spencer

      #3
      Re: Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

      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

      Big Things are made up of
      Lots of Little Things.

      "Sergey Morkovkin" <sergey@celline .com.ua> wrote in message
      news:oprvb2m9tk 80s4pa@news.luc ky.net...[color=blue]
      > Hi, guys!
      > Does anyone knows the resolution of a problem when i need to insert <link>[/color]
      or <script> tag into HEAD section dynamically?[color=blue]
      > I was trying few ways to do this: 1) RegisterClientS criptBlock inserts[/color]
      script right after form.[color=blue]
      > 2) RegisterStartup Script inserts script before post form.
      > 3) Page.Controls.A dd(new LiteralControl( "<LINK rel='stylesheet '[/color]
      href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
      but inserts only the last one tag to the end of a page.[color=blue]
      >
      > P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src[/color]
      attribute of an existing tag.[color=blue]
      >
      > --
      > 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[/color]


      Comment

      • Ezra Epstein

        #4
        Re: Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

        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" <sergey@celline .com.ua> wrote in message
        news:oprvb2m9tk 80s4pa@news.luc ky.net...[color=blue]
        > Hi, guys!
        > Does anyone knows the resolution of a problem when i need to insert <link>[/color]
        or <script> tag into HEAD section dynamically?[color=blue]
        > I was trying few ways to do this: 1) RegisterClientS criptBlock inserts[/color]
        script right after form.[color=blue]
        > 2) RegisterStartup Script inserts script before post form.
        > 3) Page.Controls.A dd(new LiteralControl( "<LINK rel='stylesheet '[/color]
        href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
        but inserts only the last one tag to the end of a page.[color=blue]
        >
        > P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src[/color]
        attribute of an existing tag.[color=blue]
        >
        > --
        > 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[/color]


        Comment

        • Slava Tihonyuk

          #5
          Re: Insert SCRIPT or LINK tag into a HEAD section DYNAMICALLY

          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" <sergey@celline .com.ua> wrote in message
          news:oprvb2m9tk 80s4pa@news.luc ky.net...[color=blue]
          > Hi, guys!
          > Does anyone knows the resolution of a problem when i need to insert <link>[/color]
          or <script> tag into HEAD section dynamically?[color=blue]
          > I was trying few ways to do this: 1) RegisterClientS criptBlock inserts[/color]
          script right after form.[color=blue]
          > 2) RegisterStartup Script inserts script before post form.
          > 3) Page.Controls.A dd(new LiteralControl( "<LINK rel='stylesheet '[/color]
          href='include/inputbox.css' type='text/css'>")); (or AddAt method) Works,
          but inserts only the last one tag to the end of a page.[color=blue]
          >
          > P.S. I need to INSERT new LINK or SCRIPT tag but to change the href or src[/color]
          attribute of an existing tag.[color=blue]
          >
          > --
          > 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[/color]


          Comment

          Working...