简体   繁体   中英

Use masterpage CSS and JavaScript in ASP form child-page

I have a master page which containing few CSS links and java scripts.

<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server">

<script src="Scripts/slides.min.jquery.js" type="text/javascript"></script>

<asp:ContentPlaceHolder id="head" runat="server">
       <script  language="javascript" type="text/javascript">
           $(document).ready(
            function () {
                $("#pikame").PikaChoose();

            });
       </script>
</asp:ContentPlaceHolder>

`

I want to use this JavaScript and css style files ,in child ASP form page which has inherited from above master page.

<%@ Page Title="" Language="C#" asterPageFile="~/MasterPage.master"AutoEventWireup="true" CodeFile="LeadInformation.aspx.cs" Inherits="LeadInformation" %>

<%@ MasterType TypeName="MasterPage" %>

Seems this way not working. Please anyone help me to use masterpage CSS and JavaScript in child-page to me. Tx in advanced.

Put your script outside the ContentPlaceHolder tag. Just put it in the head section normally.

The ContentPlaceHolder tag should be empty in the Master Page - its contents will be replaced by the asp:Content tags in the Pages.

You can check if it's being rendered properly by browsing to the page and right-click -> View Source.

<asp:ContentPlaceHolder id="head" runat="server">

is used to provide script,css that are specific to only that child page

so if you want the scripts/css to be applied to the child pages just place it normally in the master page head section and outside head ContentPlaceHolder in master page..

Hope this helps....

First, child pages are not inherited from master pages. It's the same page. Second, you don't need MasterType directive to access javascript.

So just consider masterpage and child page to be one as it will be one page when it renders to Browser and javascript runs on browser. So you can place your javascript/CSS anywhere in the head section of master page and access it from any of the child page in a same manner as they are on the same page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM