Master and Content js

D

David C

Can I have javascript in both the Master Page and inside the Content page?
I want to keep shared js inside the Master and have additional js inside the
content page. I tried using the ContentPlaceHolderID="head" in the content
page but then the Master Page "head" was ignored. My Master Page "head"
example is below. Thanks.

David


<asp:ContentPlaceHolder ID="head" runat="server">
<script language="javascript" type="text/javascript">
function getScrollBottom(p_oElem) {
return p_oElem.scrollHeight - p_oElem.scrollTop -
p_oElem.clientHeight;
}
function opentasks(stid) {
var surl = 'Tasks.aspx?tid=' + stid;
//give new window a name so we know where we came from when
closing task screen
window.open(surl, "viahome",
"height=475,width=800,status=yes,toolbar=no,menubar=no,location=no");
}
function openemail(spid) {
var surl = 'Tasks.aspx?pid=' + spid;
//give new window a name so we know where we came from when
closing task screen
window.open(surl, "viahome",
"height=475,width=760,status=yes,toolbar=no,menubar=no,location=no");
}
</script>
</asp:ContentPlaceHolder>
 
T

ThatsIT.net.au

it seems to me you have your java script inside the placceholder, it should
be outside

take a look at this master page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
<!--
javascript

// -->
</script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="masterForn" runat="server">
<asp:ContentPlaceHolder ID="body" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
 
G

Gregory A. Beamer

Can I have javascript in both the Master Page and inside the Content
page? I want to keep shared js inside the Master and have additional
js inside the content page. I tried using the
ContentPlaceHolderID="head" in the content page but then the Master
Page "head" was ignored. My Master Page "head" example is below.
Thanks.

yes, but yours is inside the placeholder, which will be overwritten by the
actual page. As long as the scripts do not conflict, which can be tested in
a single page without a master, you can run as many as you want (master
page, page, control). This does not mean running scripts at every level is
a great idea, but it is possible.

Peace and Grace,
 
G

Gregory A. Beamer

OK, thanks. So what is the purpose of the "head" ContentPlaceholder?
Thanks.

So you can, at the page level, embed in scripts.That would be in the
asp:Content region for the head ContentPlaceholder. Do not place code in
the Content PlaceHolder unless you want it overwritten in some pages. I
hope this is clear, as I am in the middle of numerous things. ;-)

Peace and Grace,
 
H

Hillbilly

WAIT A MINUTE WAIT A MINUTE WAIT A MINUTE

Are you all gone off on vacation or what? All --SHARED-- JavaScript should
be in a linked file which has been the best practice for years. Is that
context being ignored here?

Otherwise, embedded or inline JavaScript can be used anywhere in the .master
however in general and especially when using 3rd party script in our .master
the <script> is most frequently embedded right before the </body> element to
avoid conflicts with other script while the page is loading (to the greatest
extent possible) .

Unless your using Themes which are really FUBAR and intrusive it is really
easy to control every line of code written into the <head> of a Content page
when embedded script is unique to that particular page but all things
considered script should be written to a file that loads from the file
system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top