JQUERY DIALOG: close failed when I use load

JQUERY DIALOG: close failed when I use load

Hello everybody,
 
I have a little problem with the dialog. When I load the content of the dialog using load() method of jquery I can't close my dialog using $(this).dialog('close');
 
Here is the code I used:
  1.   $("#finishTaskDialog").load(urlFinishTask).dialog({               
                    autoOpen: true,
                    resizable: false,
                    width:560,
                    height:300,
                    modal: false,
                    overlay: {
                        backgroundColor: '#000',
                        opacity: 0.5
                    },        
                  buttons:{           
                      'Mark as finished': function(){
                            // do some stuff                                          
                           $(this).dialog('close');                                                  
                           });                           
                      },        
                'Cancel':  function() {              
                     $(this).dialog('close');       
                      }                
                  }      });


















The 'urlFinishedTask' is created before. So if I click on the cancel button, the dialog is not closed. If I close with the cross button on the title, it's closed.
 
What am I doing wrong?
 
Jamila