none
ResolveURL and Master Pages

    Question

  • Hi all,

    I am having issues with importing CSS files within my master page. The issue is ResolveURL does not work properly in returning paths in some cases.

    For example, this code works fine in some master pages and does not work properly in other master pages:

    <link href="<%# ResolveUrl("App_Themes/Standard/Default.css") %>" rel="stylesheet" type="text/css" />

     

     

    If the above is replaced with

    <link href="<%= ResolveUrl("App_Themes/Standard/Default.css") %>" rel="stylesheet" type="text/css" />

    then it works fine only in some master pages

    Has anyone encountered such issues in importing CSS and JS files using ResolveURL? Is there a standard way to import these files from master pages?

    • Moved by Alan_chen Thursday, August 05, 2010 2:47 AM off topic (From:Visual C# General)
    Wednesday, July 28, 2010 11:01 AM

All replies

  • ResolveURL will return the path "relative" to the "masterpage".

    you can utilize BaseURL as a workaround for your problem, please refer: http://aspnetresources.com/blog/linking_stylesheets_from_master_pages

    Hope this helps...

    Please post ASP.NET questions at http://forums.asp.net/ for faster responses. Thanks.

     


    Best Regards, SK *** Please mark as Answer, if this reply helps you***
    Thursday, July 29, 2010 6:21 AM
  • Hi YJShah,

     

    Welcome to MSDN forum!

    Here is a link shows how to import master page.

    http://aspnetresources.com/blog/more_on_url_rebasing_in_master_pages

    I often drag the .css files in the solution files to .aspx pages. It will automatically generate the code like:

    <link href="Library/CSS/MasterPageStyle.css" rel="stylesheet" type="text/css" />

     

     

    Hope these helps, if you have any problems, please feel free to let me know.

     

    Best Regards,

    Alan Chen

    ________________________________________

    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Monday, August 02, 2010 9:38 AM
  • for next viewer:

    add this code to Page_Load of MasterPage

            Page.Header.DataBind();//resolve the script binding error

    this code rebind the header after page load and ResolveUrl Work fine ;)


    you can win, if you want.

    Thursday, January 10, 2013 3:52 PM