Last post Oct 19, 2009 01:03 PM by RichardD
Oct 18, 2009 07:50 AM|Lukrs|LINK
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";
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...
Oct 18, 2009 10:58 AM|mbanavige|LINK
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");
Oct 19, 2009 01:03 PM|RichardD|LINK
Try using the
ResolveUrl method from your control:
link.Href = this.ResolveUrl("mainMenu.css");