Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How to add JavaScript in a masterpage and content page?
Posted
Updated 27-May-10 2:23am
v2

in master page
should be in <header> tag

in content page it should be below
<asp:contentplaceholder xmlns:asp="#unknown"> tag</asp:contentplaceholder></header>
 
Share this answer
 
Just add the script tags in the master page or content page and the javascripts can be included in them.

Eg:
HTML
<script>
 // My Javascripts here!
</script>
<form>
<!-- Master Page-->
</form>


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!
 
Share this answer
 
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
</script></head>
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.
 
Share this answer
 
Comments
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?
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

http://www.dotnetcurry.com/ShowArticle.aspx?ID=274
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900