jquery ui dialog in asp.net mvc3 doesn't open on second time
        Posted  
        
            by 
                giri
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by giri
        
        
        
        Published on 2012-06-25T15:12:41Z
        Indexed on 
            2012/06/25
            15:15 UTC
        
        
        Read the original article
        Hit count: 333
        
asp.net-mvc-3
|jquery-ui-dialog
when i click the New Trade button in the form it opens jquery ui dialog. but, i have link button in the gridview when i click the link button it should open jquery ui dialog, it opens jquery ui dialog before clicking the new trade button. but, after clicking the new trade button, if i click link button in the gridview it invoke "ViewTradeDialog(id)" function, the dialog doesn't open, it shows error message "$vwdia.html(data).dialog is not a function". my code follows:
    @using (Html.BeginForm("NewTrade", "Trade", FormMethod.Post, new { id = "searchForm" }))
{
    <div id="searchbtn">
        <input id="btn_newtrade" type="submit" value="New Trade" />
    </div>
}
jquery code
  <script type="text/javascript">
 $(function () {
     var $loading = $('<img src="../../loading.gif" alt="loading">');
     var $dialog = $('<div></div>').append($loading);
     $('#searchForm').submit(function (e) {
         var url = this.action;
         $.ajax({
            autoOpen: false,
             url: url,
             success: function (data) {
                 $dialog.html(data).dialog({
                     zIndex:1,
                     width: 1400,
                     height: 600,
                     resizable: false,
                     title: 'New Trade Details',
                     modal: true,
                     buttons: {
                         "close": function () {
                             $dialog.dialog('close');
                         },
                         "Add Trade": function () {
                             $dialog.dialog('close');
                             $.ajax({
                                 type: 'POST',
                                 url: url
                             });
                         }
                     }
                 });
             }
         });
         return false;
     });
 });
 function ViewTradeDialog(id) {
     alert(id);
     var $vwdia = $('<div></div>');
     var url = '/Trade/ViewTrades?tradeid=' + id;
     $.ajax({
         url: url,
         success: function (data) {
             $vwdia.html(data).dialog({
                 width: 600,
                 height: 600,
                 resizable: false,
                 title: 'View Trade Details',
                 modal: false,
                 buttons: {
                     "close": function () {
                         $vwdia.dialog('close');
                     }
                 }
             });
         }
     });
     return false;
 }
© Stack Overflow or respective owner