Change <link> href attribute dynamically

Discussion in 'ASP .Net' started by Simon Gorski, Mar 6, 2004.

  1. Simon Gorski

    Simon Gorski Guest

    Hello Amir,
    "Amir Eshterayeh" <> schrieb im Newsbeitrag
    news:...
    > 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(sender As Object, e As EventArgs)
    > myhead.InnerHtml &="<LINK href=""Stylesone.css"" type=""text/css""
    > rel=""stylesheet"">"
    > 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?)


    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>

    > 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?)

    You have to declare the myhead in the code-behind:
    protected System.Web.UI.HtmlControls.HtmlControl myhead;



    mfg simo g.
     
    Simon Gorski, Mar 6, 2004
    #1
    1. Advertising

  2. 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.

    http://www.codeproject.com/aspnet/page_templates.asp


    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Amir Eshterayeh" <> wrote in message
    news:...
    > 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(sender As Object, e As EventArgs)
    > myhead.InnerHtml &="<LINK href=""Stylesone.css"" type=""text/css""
    > rel=""stylesheet"">"
    > 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
    >
    >
     
    Manohar Kamath [MVP], Mar 6, 2004
    #2
    1. Advertising

  3. 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(sender As Object, e As EventArgs)
    myhead.InnerHtml &="<LINK href=""Stylesone.css"" type=""text/css""
    rel=""stylesheet"">"
    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
     
    Amir Eshterayeh, Mar 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joel Leong
    Replies:
    0
    Views:
    646
    Joel Leong
    Feb 22, 2005
  2. Replies:
    3
    Views:
    504
  3. Simon Gorski

    Change <link> href attribute dynamically

    Simon Gorski, Mar 6, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    405
    Amir Eshterayeh
    Mar 6, 2004
  4. Soren Vejrum
    Replies:
    4
    Views:
    771
    Lasse Reichstein Nielsen
    Jul 5, 2003
  5. Jamie Jackson

    Disable Link from HREF Attribute?

    Jamie Jackson, Oct 25, 2004, in forum: Javascript
    Replies:
    4
    Views:
    248
    Jamie Jackson
    Oct 25, 2004
Loading...

Share This Page