2011-12-13 34 views
1

我的代码在我确认之前删除了项目。我确认后如何进行更改以让其删除项目。下面是javascript代码:如何在我确认后修改要删除项目的代码?

<script type="text/javascript"> 
    var _source; 
    var _popup; 

    function showChild_Delete(source) { 
     this._source = source; 
     this._popup = $find('popupChild_Delete'); 
     this._popup.show(); 
    } 

    function btnChild_Delete_Click() { 
     this._popup.hide(); 
     __doPostBack(this._source.name, ''); 
    }      
</script> 

asp.net代码调用JS代码:

<asp:ImageButton ID="btnChild_Delete" runat="server" SkinID="delete" OnClientClick="showChild_Delete(this); return false;" 
                CommandName="deleteChild" CausesValidation="False" CommandArgument='<%# Eval(childID) %>' /> 

C#代码:

if (e.CommandName == "deleteChild") 

    { 
     hashTable.Add(childID, e.CommandArgument); 
     sqlData.GetDataTable(sproc_delChild, hashTable); 

     gvChild.SelectedIndex = -1; 
     pnlChild_Upload.Visible = false; 
     this.upnlChildUpload.Update(); 

     RefreshChild(); 
    } 

我会明白任何帮助。

回答

0

你会想做些什么客户端的JavaScript促使他们这样做之前,接受他们的决定......

<script type="text/javascript"> 
    function btnChild_Delete_Click() { 
     this._popup.hide(); 

     // the _doPostBack is triggering the delete. simply writing something here. 
     if (!confirm('Are you sure?')) return; 

     __doPostBack(this._source.name, ''); 
    }      
</script> 

编辑:有一个程式化的确认窗口要做到这一点我会做下面的事情(例子是伪代码来举例逻辑流程)。

  1. 作出DIV确认删除。正如你在CSS喜欢和隐藏它(通过使其显示风格化它:none或关闭屏幕边缘

    <div id="confirmationBox"> 
        <p>Are you sure?</p> 
        <button id="doDelete">Delete</button> 
    </div> 
    
  2. 改变你的脚本调用一个函数,显示/隐藏确认DIV:

    function buttonConfirmDelete_Click { 
        // 1. display the confirmation box. 
    } 
    
    function buttonDoDelete_Click { 
        __doPostBack(this._source.name, ''); 
        // 2. hide the confirmation box. 
    } 
    

结果是现有的删除按钮即可推出删除按钮实际执行回呼其现在包含弹出的确认窗口中。

当然有更干净的方法来做到这一点,但似乎你正在寻找一个快速和简单的解决方案。

这回答你的问题?

+0

嗨。感谢您的答复。它的作品,但给浏览器的窗口是不同的风格与我的网站。像窗口的标题,颜色,大小一样。我该如何解决这个问题? – lawzlo 2011-12-13 18:35:16

0
function btnChild_Delete_Click() { 
    if (!confirm('Are you sure you want to delete?')) return; 
    this._popup.hide(); 
    __doPostBack(this._source.name, ''); 
}