2012-05-16 87 views
0

我正在使用中继器显示数据行。每一行都有一个删除图像按钮。我想用jQuery UI添加一个确认对话框。当单击删除图像按钮时,对话框将正确显示。我不确定的是当在对话框中单击OK按钮时,如何从jQuery调用Image按钮的事件处理程序。ASP.Net图像按钮使用jQuery UI对话框删除确认

回答

0

你可以做一些这样的事情,检查Jquery Dialogbox示例, 绑定Repeater时附加事件处理程序。这样

yourbutton.Attributes.Add("onclick","Deletbox('" + yourDeleteID + "'))"; 

javascript函数:

var deleteId;//this the global variable to hold the value 


function Deletebox(ID) 
{ 
    ("#YourDialog").data('DeleteID',ID).dialog('open'); 
} 

这对于对话框初始化

 $("#YourDialog").dialog({ 
        modal: true, //this will make a modal form 
           open:function() 
           { 
             deleteId=$(this).data('DeleteID'); 
           }, 
        buttons: { // this is the buttons which you are going to show in box 
         "Delete all items": function() { 
          CallYourdeletionMethodFromServer(deleteId)// by using $.Ajax function 
         }, 
         Cancel: function() { 
          $(this).dialog("close"); 
         } 
        } 
       }); 
+0

我有一个repeater_ItemCommand事件处理程序有线了其获取从CommandArgument缺失的ID,然后调用删除记录的方法。我如何直接从jQuery调用这个事件处理程序。 – user917179

+0

您可以将ID传递给对话框,我会更新答案。 –

+0

@ user917179检查我更新了答案 –

0

你可以叫你的OK按钮单击处理__doPostBack功能。您需要保留最初点击的按钮的ID以打开对话框并将其作为第一个参数传递。

0
<div class="Parent"> 
     <div> 
      test1 
     </div> 
     <div> 
      <input type="button" value="Delete" onclick="Deletemessage(1,this);" /> 
     </div> 
    </div> 
    <div class="Parent"> 
     <div> 
      test2 
     </div> 
     <div> 
      <input type="button" value="Delete" onclick="Deletemessage(1,this);" /> 
     </div> 
    </div> 


function Deletemessage(id, obj) { 
      $('<div></div>').appendTo('body') 
        .html('<div><h6>Are you want to delete this part?</h6></div>') 
        .dialog({ 
         modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true, 
         width: 'auto', modal: true, resizable: false, 
         buttons: { 
          Ok: function() { 
           $(obj).removeAttr('onclick'); 

           //        $.ajax({ 
           //         url: '/yourPath', type: 'Post', dataType: 'json', 
           //         data: { 'id': id }, 
           //         success: function (data) { 
           $(obj).parents('.Parent').remove(); 

           //Or 

           //window.location.reload(); 

           //         } 
           //        }); 

           $(this).dialog("close"); 
          }, 
          Cancel: function() { 
           $(this).dialog("close"); 
          } 
         }, 
         close: function (event, ui) { 
          $(this).remove(); 
         } 
        }); 
     };   

现场演示中看到此链接:http://jsfiddle.net/nanoquantumtech/9NKXq/

+0

函数Deletemessage(id,name,obj) - > Deletemessage(1,'test name',this); – Thulasiram