I have the following jQuery function in my ASP 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.
I have the following jQuery function in my ASP 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.
Share Improve this question edited Nov 4, 2019 at 14:20 J. Murray 1,45011 silver badges19 bronze badges asked Jan 29, 2015 at 12:52 Sormita ChakrabortySormita Chakraborty 1,0554 gold badges21 silver badges39 bronze badges 4- did you try writing the same jquery in the page containg your UC ? – Rohit Commented Jan 29, 2015 at 12:53
-
Remove the
src
attribute from the second script tag – LcSalazar 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. – Sormita Chakraborty 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. – Sormita Chakraborty Commented Jan 29, 2015 at 13:00
1 Answer
Reset to default 4First, please check your jQuery file is importing correctly. Try checking with cdn first.
<script src="https://ajax.googleapis./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">
plete 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>