Click here to Skip to main content
Rate this: bad
good
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 2:59am
Purvuk312
Edited 27-May-10 3: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 at 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 at 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
0 Peter Leow 160
1 Mika Wendelius 156
2 Abhinav S 155
3 Sergey Alexandrovich Kryukov 115
4 TheRealSteveJudge 114
0 Sergey Alexandrovich Kryukov 8,593
1 OriginalGriff 6,536
2 Peter Leow 3,727
3 Zoltán Zörgő 3,436
4 Richard MacCutchan 2,417


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 11 Jun 2011
Copyright © CodeProject, 1999-2015
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