Click here to Skip to main content
12,957,007 members (59,307 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How to add JavaScript in a masterpage and content page?
Posted 27-May-10 1:59am
Updated 27-May-10 2:23am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

in master page
should be in <header> tag

in content page it should be below
&lt;asp:contentplaceholder xmlns:asp="#unknown"> tag</asp:contentplaceholder></header>
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just add the script tags in the master page or content page and the javascripts can be included in them.

 // My Javascripts here!
<!-- Master Page-->

If you want to add a JavaScript file to them, you can use src attribute in the script tag.

Lastly, please pick any basic book, read first and then start coding!
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

In a master page the javascript functionality must be there in head section under script tag.

<head><script type="text/javascript" language="javascript">
//javascript code goes here
In the content pages, The javascript code can be in content tag which has contentplaceholderid as head which is also there in master page as contentplaceholder in head section of master page.
Sandeep Mewara 5-Jul-10 2:20am
Reason for my vote of 1
Why to pick up old answered posts and add your answer to it?
Further similar to already suggested answer!
lovejun 8-Aug-10 4:08am
Reason for my vote of 5
good,but is there have some diffrent of the place of javascript code?
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

In master page you have <head> tag. You have to include your javascript within <script> tag inside the <head> tag....
Notice one more thing within master page <head> tag there is one ContentPlaceHolder and in child page there is one <asp:content xmlns:asp="#unknown"> tag that is refer to the master page's contentplaceholder which is within the <head> tag so whatever the content written in the <asp:content> tag within the child page, that will be considered as part of <head> tag of master page so in short you can include javascript or css in child page with the use of <asp:content> tag which is refereed to ContentPlaceHolder of <head> tag within Master page....

for more info see the link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,924
CHill60 3,550
Maciej Los 3,312
ppolymorphe 2,120
Jochen Arndt 1,973

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 11 Jun 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100