0

I try to composite scripts using this code :

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script>
        $(document).ready(function () {
            alert("asd");
        });
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager runat="server" ID="scMan1">
        <CompositeScript>
            <Scripts>
                <asp:ScriptReference Path="~/Scripts/jquery-1.4.1.js" />
            </Scripts>
        </CompositeScript>
    </asp:ScriptManager>
</asp:Content>

Seems It works fine because in HTML generated source script tag exist that contains jQuery.

<script src="/WebSite2/ScriptResource.axd?d=hX0MDGfWoeBxqyrCFnUlb_i8FIXYFH2jSHZZ8wsoh3wFhHjdmAfUYtPy5B129cjGB7udx4AYPQm_cJi8Xf7uSMn9bbw2gWuhnKTab4SQhBy8ulESCXITgKubR2QozYUq-EPeVYNsCW4jU_8hY-J9fA2" type="text/javascript"></script>

But jQuery does not work now.
When I reference script usually jQuery works.
What am i doing wrong? Thanks a lot

2 Answers 2

2

My master page looks like this:

I then add my scripts to EndPage area.

I've included the standard jQuery setup for ajax in here too.

<%@ Master AutoEventWireup="false" CodeBehind="Standard.master.cs" Inherits="NameNamespace.Standard" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title><asp:ContentPlaceHolder ID="headTitle" runat="server" /></title>
  <link rel="Stylesheet" type="text/css" href="main.css" media="screen" />
  <link rel="Stylesheet" type="text/css" href="print.css" media="print" />
  <script src="Javascript/jquery-1.4.2.min.js" type="text/javascript"></script>
  <script src="Javascript/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
  <asp:ContentPlaceHolder id="head" runat="server" />
</head>
<body>
  <form id="form1" runat="server" >
    <span id="error" style="color:red" />
    <asp:ContentPlaceHolder ID="MainContent" runat="server" />

    <script type="text/javascript">
      $.ajaxSetup({
         type: "POST",
         contentType: "application/json; charset=utf-8",
         data: "{}",
         dataFilter: function(data) {
            var msg;
            if (typeof (JSON) !== 'undefined' && typeof (JSON.parse) === 'function')
               msg = JSON.parse(data);
            else
               msg = eval('(' + data + ')');
            if (msg.hasOwnProperty('d'))
               return msg.d;
            else
               return msg;
         },
         error: function(msg) {
            $('#error').html(msg.responseText)
         }
      });
   </script>

   <asp:ContentPlaceHolder id="EndPage" runat="server" />
  </form>
</body>
</html>

Original answer.

It looks like you have the order wrong. jQuery needs to be first -- in your example you have the code that is using jQuery in the header and jQuery itself in the body.

Sign up to request clarification or add additional context in comments.

2 Comments

I want to use Script manager on master page . I can't put it in header because it should be inside Form runat=server . So I putted it in body and now other jQuery Plugins in other page that I used them in page headers not works . Is there any way ?
Yes there is a way, I will update the answer in a few minutes.
1

I think is because jQuery is used before it is included.

In the example you use the jQuery in the header $(, but jQuery core include is in the body.

1 Comment

I want to use Script manager on master page . I can't put it in header because it should be inside Form runat=server . So I putted it in body and now other jQuery Plugins in other page that I used them in page headers not works . Is there any way ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.