[RESOLVED]Where to insert Javascript on my ASP.net page

I found some useful javascript and want to use it on my ASP.net page but I dunno where to insert

my page has separate master page so no header tags etc

<script type="text/javascript">
XXXX
      </script>

For the above, should I put inside <script></Script> of my page, or inside

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content ID>

?

Also when I run localhost, ie ASP.net development server, this javascript seems to bring no effect.

Is it the javascript is turned off in development server localhost ? If so, how to turn on when I run it ?

Thanks

It is always good practice to keep javascript in the end of the page. So that it will ensure that complete page is rendered and now javascript can use DOM elements.

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

<%-- Content Start --%>

<%-- End  of the Content --%>

<%-- Javascript goes here --%> <script type="text/javascript"> XXXX </script> </asp:Content>

hi

if you want to include any file like css or js just incude in

<asp:Content ID="BodyContent" ContentPlaceHolderID="content" runat="server">
include here.

</asp:Content>

Hi hkbeer,

Thanks for your post.

As for your problem, you could refer to the below sample to add javascript.

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<%--or add javascript at here--%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script>
        function hello() {
            alert("Hello World");
        }
    </script>
    <input id="Button1" type="button" value="ClickMe" onclick="hello();" />
</asp:Content>

If you have any question about my reply, please let me know freely.

Best Regards,

Fei Han

Leave a Reply