Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): 3.x Pre-release forums (retired) > Paths in SiteFinity

Paths in SiteFinity

  • Dennis84 avatar

    Posted on Apr 18, 2007 (permalink)

    Hello all,

    I have made an own template for SiteFinity 3.0 RC1 but have a problem with paths.

    Due to the structure of the website, there are different path levels. Well, in my masterpage I have a reference to a javascript file which I have put in the subdirectory 'Javascript'. I have also put a lot of images in the 'Images' directory. Because of the different path levels I have put a base href tag in the head of the masterpage.

    Now I have a problem with my css because SiteFinity automaticly adds link href items for the stylesheets (themes). Because of my base href this path doesn't work anymore.

    Does anybody have a suggestion about how I can resolve this issue?

    Reply

  • Posted on Apr 18, 2007 (permalink)

    Hi,

    Have you thought about using <asp:Image> controls for the images and then use the "~" to make it Application relative eg "~/Images".

    For you css files you can do this too and it should convert the ~ into a application relative automatically as long as your head tag has the runat="server" property set.

    As for javascript you have to cheat a bit and put src ="<% Page.ResolveUrl("~/Js/jsfile.js") %>"  that should do the same thing.

    If you get an error about controls not being able to add because of the <% I find the easiest way around that is to wrap a PlaceHolder control around it.

    I am sure there are other ways of doing it, but this is my 2 cents...

    Reply

  • Dennis84 avatar

    Posted on Apr 20, 2007 (permalink)

    First of all, the problem is that the link css is automaticly added by SiteFinity, so I can't control it.

    I have tested the <% method but this doesn't work. My script tag is in the body of the masterpage, where it gives no error but doesn't work either. When I put the tag in my head it gives an HttpException saying it cannot modify the controls collection.

    Your method avoiding this error by putting a placeholder control around it is in my opinion a dirty method and I prefer other methods before using unnecessary div, span, placeholder etc. tags.

    Finally, the ~ in an asp:Image control doesn't work when using a base-href tag. When I remove it, it does, so that is a good option, but then I'm still stuck with my refering javascript file.

    Thanks in advance.

    Reply

  • Slavo Slavo admin's avatar

    Posted on Apr 20, 2007 (permalink)

    Hi Dennis,

    All CSS files placed in Theme folder are loaded automatically for the selected Theme by ASP.Net. Note this is ASP.Net 2.0 feature not Sitefinity’s.

    Alternatively you can add CSS links to Sitefinity’s Pages and Templates manually. Go to properties Tab for a Page or a Template and find Add Head Tags section. I suggest using “~” to resolve pats instead of using base tag. This is the common way for ASP.Net applications. So in the HREF field you should specify the path to your CSS file like this “~/styles/myfile.css”.

    Anther alternative is to create User Control and place the links to CSS and JavaScript files programmatically like this:

    1 protected void Page_Load(object sender, EventArgs e)  
    2 {  
    3         // Add Stylesheet  
    4         System.Web.UI.HtmlControls.HtmlLink link = new System.Web.UI.HtmlControls.HtmlLink();  
    5         link.Attributes.Add("rel""stylesheet");  
    6         link.Attributes.Add("type""text/css");  
    7         link.Href = this.ResolveUrl("~/styles/myfile.css");  
    8         this.Page.Header.Controls.Add(link);  
    9  
    10         // Add JavaScript  
    11         string path = this.ResolveUrl("~/Scripts/MyScript.js");  
    12         this.Page.ClientScript.RegisterClientScriptInclude("MyScript", path);  
    13 }  
    14  

    Images and hyper links should be declared like this:

    <img src="~/Images/MyImage.jpg" alt="" runat="server" /> 
    <href="~/SubFolder/Page.aspx" runat="server">My Link</a> 
     



    Kind regards,
    Slavo
    the telerik team


    Instantly find answers to your questions at the new telerik Support Center

    Reply

  • Posted on Apr 22, 2007 (permalink)

    Hi Dennis,

    Sorry I wasn't very clear everything I gave you was to give you a work around that didn't require you to use the base href.... if you want to use base href the sample code that I and Telerik supplied.  In my experience the base href causes far more problems that in fixes especially if you want to use postbacks etc on any pages etc...  So I would recommend instead using Application Relative paths instead.

    And just a note the Placeholder control doesn't render any tags in HTML so I hardly consider it an unnecessary tag? But if you want to add relative paths declaratively you need to wrap the <% %> in some sort of parent control.  The other way is to do what Telerik have said which involves far more code...

    Anyway that is my 2 cents, I have tried to use the base href before and it doesn't get pretty if you are using it with ASP.Net applications....

    Good Luck.

    Reply

  • Dennis84 avatar

    Posted on Apr 23, 2007 (permalink)

    Thank you for your reply Sean.

    I have now made some changes and I am no longer using the base-href tag.

    I've got everything working now, except for the javascript pathfinder. I've tried your suggestion, but it doesn't work. That might be because I haven't done it right. This is my code:

    1 <asp:Placeholder id="ScriptPlaceholder" runat="server">  
    2   <script src="<%="~/Javascript/Waterproef.js" %>type="text/javascript"></script> 
    3 </asp:Placeholder> 

    Reply

  • Posted on Apr 23, 2007 (permalink)

    Hi Denis,

    No problem, I only to happy from saving someone from going through the stress that I did of using the base href problem with ASP.Net.

    Code just needs to be modifed to :
    1<asp:Placeholder id="ScriptPlaceholder" runat="server">  
    2<script src="<%=Page.ResolveUrl("~/Javascript/Waterproef.js") %>type="text/javascript"></script> 
    3</asp:Placeholder>  

    The Page.ResolveUrl method is a function built in to the Page object that then will resolve the ~

    Cheers
    Sean

    Reply

  • Posted on Aug 11, 2011 (permalink)

    Hello,
    I have a image code like this
      <img src="images/css/header_bg.jpg" width="1020" height="56" alt="header" />

    When  I added like this in  page   <img src='<% =this.Page.ResolveUrl("~/images/css/header_bg.jpg")%>' width="1020" height="56" alt="header" />

    I got error

    Server Error in '/' Application.

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    How can I resolve it

    Thank You
    Roopesh

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Aug 11, 2011 (permalink)

    Hello Roopesh,

    This is a general ASP.NET error which is thrown because you need to wrap the logic you have in RadCodeBlock. You can google for other options to solve this issue.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Register for webinar
Skip Navigation LinksHome / Developer Network / Forums / Sitefinity Older Versions (3.x): 3.x Pre-release forums (retired) > Paths in SiteFinity