locked
HtmlHead link problem RRS feed

  • Question

  • User-1853544428 posted

    Hi,

    I have written a control, which is located in ~/lukrsControls/mainMenu/myControl.ascx.

    Inside of this control i do this in page_load event:

            HtmlHead head = (HtmlHead)Page.Header;
            HtmlLink link = new HtmlLink();

             
            link.Href = "lukrsControls/mainMenu/mainMenu.css";
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");

            head.Controls.Add(link);

    This code adds a link to my css inside head element. The problem is, that I would like to remove  this part of the path -> lukrsControls/mainMenu/, with some funtion that would generate this part of the link if you know what I mean.

    (this way, my control could be used in any directory)


    For example, I have a hyperlink in the same class and its NavigateUrl property is "Default.aspx?id=". When I start the application, the link automatically gets "lukrsControls/mainMenu". But the HtmlLink for my head doesn't.


    I would really appreciate any help...


    Thanks,

    LP, Lukrs

    Sunday, October 18, 2009 7:50 AM

Answers

  • User-158764254 posted

    you can use root relative syntax by using the ~/ and then just run it through Page.ResolveUrl to get ta root relative link url that can be used from anywhere on your site.

     

    // assuming the lukrsControls is a folder in the root of your project folder
    link.Href = Page.ResolveUrl("~/lukrsControls/mainMenu/mainMenu.css");


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 18, 2009 10:58 AM

All replies

  • User-158764254 posted

    you can use root relative syntax by using the ~/ and then just run it through Page.ResolveUrl to get ta root relative link url that can be used from anywhere on your site.

     

    // assuming the lukrsControls is a folder in the root of your project folder
    link.Href = Page.ResolveUrl("~/lukrsControls/mainMenu/mainMenu.css");


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 18, 2009 10:58 AM
  • User863160722 posted

    Try using the ResolveUrl method from your control:

    link.Href = this.ResolveUrl("mainMenu.css");
    Monday, October 19, 2009 1:03 PM