Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The concept of masterpage is for serverside, your browser will see the result as only one page so you can put your javascript functions on the head section of your master, and call them in your content pages if you want or in the rest of the master page.</p> <p><strong>EDIT</strong></p> <p>You can put a content place holder on your head section in your master page, so child page can include its specific script in the head if you want...</p> <p>Example</p> <pre><code>&lt;%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript" src="yourglobaljsfile.js"&gt;&lt;/script&gt; &lt;asp:ContentPlaceHolder ID="ScriptContent" runat="server" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div style="position: absolute; width: 100%; top: 0px;"&gt; &lt;asp:ContentPlaceHolder ID="OtherPlaceholer" runat="server" /&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt;yourGlobalfunction();&lt;/script&gt; &lt;/body&gt; </code></pre> <p>A child example</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;CatalogViewModel&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt; //blabla &lt;script type="text/javascript"&gt;yourSpecificfunction();&lt;/script&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server"&gt; &lt;script type="text/javascript" src="yourspecificjsfile.js"&gt;&lt;/script&gt; &lt;/asp:Content&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload