jquery doesnt work in content page when control is added

Hi ,

jQuery doesnt work in page when i try to add user control in that page . Jquery is also used in user control page. although user control jquery works in that page only.

I thinks its might be refernece src address error.

need help

Thanks

you need to add the reference of jquery in your local page also.

try to add the same in your page as well:

<script type="text/javascript" src="jquery1.4.js"></script>
<script type="text/javascript">

$(document).ready(function()
{

// do your code here

});
</script>

Ashutosh Pathak

you need to add the reference of jquery in your local page also.

it is ready added  , jquery in page works when till i donot add any user control in page.but when i add user control. the jquery doesnt work

Hi,

I got the same error earlier doing some R&D on User control and I was getting error "$ is undefined or JQuery is undefined",

but later on what i’ve done is: I just add the reference of the same in page as well as in user control and it started working. may be you should try to put your js file in your application root folder, It doesnt make any sense but it resolved my problem
that time :P

Hi,

Multiple problem can happen in your case.

There may be duplicate jQuery file reference. One in the page and one in the usercontrol. In case of something specific to usercontrol you should add the js file reference the in user control otherwise you should add in the page or master page.  To avoid
path issue you should also follow the following process-

http://forums.asp.net/p/1742058/4695188.aspx/1?Re+CSS+couldn+t+be+retrieve+

http://www.delicious.com/anupdg/filereference

Also you should add the script inside document ready.

The control reference in the selector should be attribute base of class based. In case attribute based means if your textbox is with id
mytext. you should try building selector like input[type=text][id*=mytest].

asteranup

In case of something specific to usercontrol you should add the js file reference the in user control otherwise you should add in the page or master page.

Yes i have tried this one , when i add reference only on user control the page jquery doestn work at all , vice versa.

asteranup

http://forums.asp.net/p/1742058/4695188.aspx/1?Re+CSS+couldn+t+be+retrieve+

I am already using clientresolveurl for these scripts.

asteranup

you should add the script inside document ready.

Can you please tell mw how i can add scripts inside document ready ? should i delete it from head section also ?

Hi,

shan000

Can you please tell mw how i can add scripts inside document ready ? should i delete it from head section also ?

If you have your script inside $(document).ready, then you need not worry about the position of the script. You can place anywhere on the page or user control.

http://docs.jquery.com/Tutorials:Introducing_$%28document%29.ready%28%29

asteranup

If you have your script inside $(document).ready, then you need not worry about the position of the script. You can place anywhere on the page or user control.

Following is the code : but problem doesnt solve. following is the script of content page :

Please have a look as its been a week im stucked with this problem.

<asp:Content ID="Content1" ContentPlaceHolderID="pagehead" Runat="Server">
	<title runat ="server"  id="pgTitle"  />
	<meta name="keywords" id="pgKeyword" runat ="server"  content="" />
	<meta name="description" content="" id="pgDescription" runat="server" />    

 
 
<script src="<%= ResolveClientUrl("~/scripts/jquery-1.6.2.min.js") %>" type="text/javascript"></script>
<script src="<%= ResolveClientUrl("~/scripts/jquery-ui-1.8.17.custom.min.js") %>" type="text/javascript"></script>
<link href="<%= ResolveClientUrl("~/styles/jquery-ui-1.8.17.custom.css") %>" rel="stylesheet" type="text/css" />

<script src="../../scripts/jquery.jqzoom-core-pack.js" type="text/javascript"></script>
<link rel="stylesheet" href="../../styles/jquery.jqzoom.css" type="text/css"/> 

<script type="text/javascript">
 
	$(document).ready(function () {
		$('.jqzoom').jqzoom({
			zoomType: 'standard',
			lens: true,
			preloadImages: false,
			alwaysOn: false,
			zoomWidth: 200,
			zoomHeight: 200,
			xOffset: 90,
			yOffset: 30,
			position: 'right'
		});
		//$('.jqzoom').jqzoom();
 
		$('#tabs').tabs();
		// Dialog 
		$('#ReplyDialog').dialog({
			autoOpen: false,
			modal: true,
			show: "slide",
			width: 600,
			buttons: {
				"Send Mail"function () {
					var dataToSend = { MethodName: 'SendReply', Reply: document.getElementById('<%= txtReply.ClientID %>').value };
					//var id = $.readQS('productId');
					var options =
						{
							url: '<%=ResolveUrl(string.Format("~/classifieds/details/electricDetails.aspx?productId={0}", Request.QueryString["productId"])) %>',
							data: dataToSend,
							dataType: 'JSON',
							type: 'POST',
							success: function () { $(this).dialog("close"); }
						};
					$.ajax(options);
 
 
 
				},
				"Cancel"function () {
					$(this).dialog("close");
				}
			}
		});
 
 
		// Dialog Link
		$('#ReplyDialog_link').click(function () {
			$('#ReplyDialog').dialog('open');
			return false;
		});
		//hover states on the static widgets
		$('#ReplyDialog_link, ul#icons li').hover(
					function () { $(this).addClass('ui-state-hover'); },
					function () { $(this).removeClass('ui-state-hover'); }
				);
	});
</script>
 
	  <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
<script type ="text/javascript"  language ="javascript">    !function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = "//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); } } (document, "script""twitter-wjs");</script>
<script type="text/javascript">
	(function () {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
</script>
<title >
</title>
 
 
</asp:Content>






following is the code of user control :

<script src="<%= ResolveClientUrl("~/scripts/jquery-1.6.2.min.js") %>" type="text/javascript"></script>
 <script src="<%= ResolveClientUrl("~/scripts/jquery-ui-1.8.17.custom.min.js") %>" type="text/javascript"></script> 
<link href="<%= ResolveClientUrl("~/styles/jquery-ui-1.8.17.custom.css") %>" rel="stylesheet" type="text/css" />
  <script type ="text/javascript" >
                    $(document).ready(function () {
 
               
 
                        $('#categorydialog').dialog({
                            autoOpen: false,
                            modal: true,
                            width: 600,
                            show: "slide",
                            buttons: {
 
                                "Accepted"function () {
                                    $(this).dialog("close");
 
                                }
                            }
                        });
                        $('#categorydialog_link').click(function () {
                            $('#categorydialog').dialog('open');
                            return false;
                        });
 
                    });           
                        
    </script>


Thanks

Try moving all of your jQuery to the ready function in your main page. Then, replace your click events with live click events. (ie. jQuery("someselector").live("click",function(){

//the click events

});

That way if the selector hasn’t been created yet, the click event will be attached whenever it is created.

Leave a Reply