ResolveUrl not working in master page in asp.net

4.4k Views Asked by At

Ok, I have some code and sanapshot to explain my problem,

I have a master page Main.Master in which I have includes all the references of css and jquery as

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="CTVideos.Main" %>
<%@ Register Src="uc/LeftNav.ascx" TagName="LeftNav" TagPrefix="uc4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta charset="UTF-8" />
    <title>Video</title>
    <meta name="viewport" content="initial-scale=1.0, width=device-width" />
    <!-- Style Sheets -->
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/bootstrap.min.css") %>" />
    <!-- Font Icons -->
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/font-awesome.min.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/ionicons.min.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/socicon-styles.css") %>" />
    <!-- Font Icons -->
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/hover-min.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/owl.carousel.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/animate.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/css-menu.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/loader.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/styles.css") %>" />
    <link rel="stylesheet" type="text/css" href="<%#ResolveUrl("~/css/responsive.css") %>" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body id="index-v2">
    <form id="form1" runat="server">
        <uc1:LeftNav runat="server" ID="LeftNav" />
        <asp:ContentPlaceHolder ID="cpl_chlid" runat="server">
        </asp:ContentPlaceHolder>
    </form>
    <!-- Scripts -->
    <script src="<%#ResolveUrl("~/js/wow.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/jquery-1.12.3.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/bootstrap.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/owl.carousel.min.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/css-menu.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/jquery.validate.js")%>"></script>
    <script src="<%#ResolveUrl("~/js/custom.js")%>"></script>
</body>
</html>

And in Main.Master page load event

public partial class Main : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.DataBind();
    }
}

And root directory of my project is like that

enter image description here

WebForm1, WebForm2 and other WebForms inside the View folder are inherited from the Main.Master page. WebForm1, WebForm2 are loaded fine as expected but all the WebForms inside View folder are not loaded properly, there design is disturbed

1

There are 1 best solutions below

1
On BEST ANSWER

Remove ResolveUrl from all css files and attach them simple beacuse ResolveUrl is needed only for scripts. Just remove the ResolveUrl from css files and it will work perfectly.

Solution 2 -

You can replace # sign with = in ResolveUrl

Example

<%# ResolveUrl("~/js/wow.min.js") %> With <%= ResolveUrl("~/js/wow.min.js") %>

Solution 2 worked for me.