Chiako
Chiako

Reputation: 744

Access master page from different folder

I would think this should be easy but not sure how to fix.

I have inside Main folder a page named 01.aspx

01.aspx page should inheritance of products.master

Project root existent inside products.master

Like the photo below:

enter image description here

I use of bellow code but nothing dosent work javascripts,image and ...

01.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Products.master" AutoEventWireup="true" CodeFile="01.aspx.cs" Inherits="Main_01" %>

Products.master

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Products.master.cs" Inherits="Products" %>

<html>
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
    <%-- product --%>
    <link rel='stylesheet' href='js/test/woocommerce-product.css' type='text/css' media='all' />
    <link rel='stylesheet' href='js/test/style-product.css' type='text/css' media='all' />
    <script type='text/javascript' src='js/test/jquery-migrate-product.min.js'></script>
    <script type='text/javascript' src='js/test/include_scripts-product.js'></script>...

Upvotes: 1

Views: 1304

Answers (2)

mohammad
mohammad

Reputation: 361

You should use of ResolveUrl in the src inside master page

Script:

<script type="text/javascript" src='<%= ResolveUrl("js/jquery-1.11.1.min.js") %>'></script>

Img:

<img src='<%= ResolveUrl("images/Logo.png")%>' />

Upvotes: 2

Sami
Sami

Reputation: 3800

Use Page.ResolveClientUrl

<script type='text/javascript' src="<%= Page.ResolveClientUrl('~/js/test/jquery-migrate-product.min.js') %>" ></script>

<script type='text/javascript' src="<%= Page.ResolveClientUrl('~/js/test/include_scripts-product.js') %>" ></script>

Another possible solution:

<script type="text/javascript" 
    src="<%# ResolveUrl("~/ScriptFolder/JSFile.js") %>">

Then in Code Behind of Master page under Page_Load Event

Page.Header.DataBind();

It works for either jQuery and JavaScript as well as CSS just you need to change your path in ResolveUrl which file you want to handle CSS, JavaScript, jQuery

Hope this helps !

Upvotes: 0

Related Questions