Change <link> href attribute dynamically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amir Eshterayeh

    Change <link> href attribute dynamically

    Dear Friends
    I want to change the name of my css file dynamically so
    as Mr. Jos Branders helped me, I can change the <head> tag into an HTML
    control like this:
    <head id="myhead" runat="server">
    ...permanent content here...
    </head>
    so that I can modify it from code like this:

    Sub Page_Load(sende r As Object, e As EventArgs)
    myhead.InnerHtm l &="<LINK href=""Styleson e.css"" type=""text/css""
    rel=""styleshee t"">"
    End Sub

    But when I run the code, I got this error:
    The type or namespace name 'myhead' could not be found (are you missing a
    using directive or an assembly reference?)

    Please help.

    Thanks in advance. Andy


  • Simon Gorski

    #2
    Re: Change &lt;link&gt; href attribute dynamically

    Hello Amir,
    "Amir Eshterayeh" <aeshterayeh@ho tmail.com> schrieb im Newsbeitrag
    news:epFJJx5AEH A.2632@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Dear Friends
    > I want to change the name of my css file dynamically so
    > as Mr. Jos Branders helped me, I can change the <head> tag into an HTML
    > control like this:
    > <head id="myhead" runat="server">
    > ...permanent content here...
    > </head>
    > so that I can modify it from code like this:
    >
    > Sub Page_Load(sende r As Object, e As EventArgs)
    > myhead.InnerHtm l &="<LINK href=""Styleson e.css"" type=""text/css""
    > rel=""styleshee t"">"
    > End Sub
    >
    > But when I run the code, I got this error:
    > The type or namespace name 'myhead' could not be found (are you missing a
    > using directive or an assembly reference?)[/color]

    I'd use a literalControl:
    <head>
    <asp:Literal id="styles" runat="server"> </asp:Literal>
    </head>

    Or a protected variable:
    Dim Protected _styleSheet As String
    _styleSheet = "<LINK href=Stylesone. css type=text/css>"

    <head>
    <%= styleSheet %>
    </head>
    [color=blue]
    > But when I run the code, I got this error:
    > The type or namespace name 'myhead' could not be found (are you missing a
    > using directive or an assembly reference?)[/color]
    You have to declare the myhead in the code-behind:
    protected System.Web.UI.H tmlControls.Htm lControl myhead;



    mfg simo g.


    Comment

    • Manohar Kamath [MVP]

      #3
      Re: Change &lt;link&gt; href attribute dynamically

      LINK is not really a property of the Page class. One thing you can do is, to
      use template approach -- change the LINK dynamically in the template
      control.




      --
      Manohar Kamath
      Editor, .netWire



      "Amir Eshterayeh" <aeshterayeh@ho tmail.com> wrote in message
      news:epFJJx5AEH A.2632@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Dear Friends
      > I want to change the name of my css file dynamically so
      > as Mr. Jos Branders helped me, I can change the <head> tag into an HTML
      > control like this:
      > <head id="myhead" runat="server">
      > ...permanent content here...
      > </head>
      > so that I can modify it from code like this:
      >
      > Sub Page_Load(sende r As Object, e As EventArgs)
      > myhead.InnerHtm l &="<LINK href=""Styleson e.css"" type=""text/css""
      > rel=""styleshee t"">"
      > End Sub
      >
      > But when I run the code, I got this error:
      > The type or namespace name 'myhead' could not be found (are you missing a
      > using directive or an assembly reference?)
      >
      > Please help.
      >
      > Thanks in advance. Andy
      >
      >[/color]


      Comment

      Working...