Click here to Skip to main content
12,401,864 members (63,019 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET Beginner
How to add JavaScript in a masterpage and content page?
Posted 27-May-10 1:59am
Purvuk312
Updated 27-May-10 2:23am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

in master page
<script> should be in <header> tag

in content page it should be below
<asp:contentplaceholder xmlns:asp="#unknown"> tag</header></script>
  Permalink  
Rate this: bad
 
good
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.

Eg:
<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!
  Permalink  
Rate this: bad
 
good
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
</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.
  Permalink  
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?
Rate this: bad
 
good
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

http://www.dotnetcurry.com/ShowArticle.aspx?ID=274
  Permalink  
v3

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


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 11 Jun 2011
Copyright © CodeProject, 1999-2016
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