tags:

views:

82

answers:

1

I am dynamically loading a user control on a click of a checkbox. I need to run a post on the Jquery when a button is clicked on the user control. When I Load my User Control, I cannot run

$(document).ready(function(){
     alert('I am here!!');
});  as a test.

Any Ideas. or do I need a $.getScript() ?.

A: 

I would put the code in the callback of the load method.

$('#content').ajax({
     url: '/some/url',
     ...
     success: function(data) {
         $('#content').html( data.Html ); // assumes JSON with Html parameter
         $('#content').find('input[type=submit]').click( function() {
             ...do your submit...
             return false; // cancel default action
         }),
     ...
});

Or, perhaps -- depending on the situation -- set it up with a live handler.

$('#content').find('input[type=submit]').live('click', function() {
    ... do your submit...
    return false;
});
tvanfosson
I am unable to run that, I am dynamically loading the User control.
Greens
I am loading User COntrol using http://weblogs.asp.net/sanjeevagarwal/archive/2008/07/29/Dynamically-create-ASP.NET-user-control-using-JQuery-and-JSON-enabled-Ajax-Web-Service.aspx
Greens
Looks like you are using AJAX/JSON instead of load. In that case, put the code in the success callback. Will update.
tvanfosson
Thank you
Greens
Can we run multiple functions in Success; ex dump the htnl in the div and attach the click event for the buton in the user control.
Greens
Yes. It's just a function that will be executed after the AJAX call has returned. I omitted the data parameter to it, but I'll update.
tvanfosson