2

I have the following jQuery function in my ASP.net user control:

<head>
<title></title>
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="~/Scripts/jquery-1.4.1.js">

    $(document).ready(function () {
        alert("In Jquery");
        $("[id*=RadioButtonListYesNo]").change(function () {
            alert("In Jquery");
            var res = $('input[type="radio"]:checked').val();

            if (res == '1') {
                $("#divFAFMQues").css("visibility", "hidden");
                $("#divFAFM").css("visibility", "hidden");
            }
            else {

                $("#divFAFMQues").css("visibility", "visible");
                $("#divFAFM").css("visibility", "visible");
            }
        });
    });
    </script>



</head>

The document.ready function is not getting fired when the page containing the user control is getting loaded. Please help.

4
  • did you try writing the same jquery in the page containg your UC ? Commented Jan 29, 2015 at 12:53
  • Remove the src attribute from the second script tag Commented Jan 29, 2015 at 12:54
  • i tried to add it in the page containing UC like the following:<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script language="javascript" type="text/javascript" src="~/Scripts/jquery-1.4.1.js"> $(document).ready(function () { alert("In Jquery"); }); </script> </asp:Content> It did not fire, so I tried to add it in the master page head section, still it is not firing. Commented Jan 29, 2015 at 12:57
  • when i remove the src attribute from the second tag, it is giving me JS Runtime error: Object Expected. It is only when i add the src tag, the error is not encountered. Commented Jan 29, 2015 at 13:00

1 Answer 1

4

First, please check your jQuery file is importing correctly. Try checking with cdn first.

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

Try to remove src element from your 2nd script tag:

<script language="javascript" type="text/javascript" src="~/Scripts/jquery-1.4.1.js">

to

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

complete code:

<asp: Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
         $(document).ready(function() {
                    alert("In Jquery");
                });
    </script>
</asp:Content>
Sign up to request clarification or add additional context in comments.

12 Comments

when i remove the src attribute from the second tag, it is giving me JS Runtime error: Object Expected. It is only when i add the src tag, the error is not encountered.
working fine for me..please check for syntax errors.
Thisis what I have written : <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <script language="javascript" src="~/Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script language="javascript" type="text/javascript" src="~/Scripts/jquery-1.4.1.js"> $(document).ready(function () { alert("In Jquery"); }); </script> </asp:Content> Can you please check if there is a difference in what you have written?
thanks for that, but i am still facing the same problem. i am getting "Object Expected" error at runtime. Should I put some tag like AutoPostBack=true or something like that somewhere?
there could be other possiblities....1) check if your jQuery is importing successfully. 2) check if you are using __doPostBack
|

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.