Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a child page which is inherited from a master page, i want to write jquery in the child page. where should i write the <script>.. tag in content page........plz help
Posted

First of all. Javascript should be written as js-files and then added with script-tags. It will make your html cleaner and save bandwidth.

But generally it doesn't matter where you put it. Just wrap it in a script tag anywhere in the page.
Make sure you don't use variables which are not declared yet. for example if you add a bunch of javascript at the bottom of your masterpage, you can't access those functions/variables before these scripts are loaded.

It's a good idea to wrap your javascript with $(document)ready(). Then it will not be executed before page is finished loading.

JavaScript
$(document).ready(function() {
   // put all your jQuery goodness in here.
});
 
Share this answer
 
v2
I prefer to use content place holder for each section.
See following code for clarification

ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="" Inherits="System.Web.Mvc.ViewPage%>

<asp:content id="Content2" contentplaceholderid="HeadContentPlaceHolder" runat="server" >
     <style type="text/css">
     </style>
</asp:content>

<asp:content id="Content3" contentplaceholderid="MenuPlaceHolder" runat="server" >
</asp:content>

<asp:content id="Content1" contentplaceholderid="MainContentPlaceHolder" runat="server" >
</asp:content>

<asp:content id="Content4" contentplaceholderid="ScriptPlaceHolder" runat="server" >
    <script type="text/javascript">
    </script>
</asp:content>
 
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