我确认后如何修改代码删除项目

How to modify the code to delete item after I confirm?

本文关键字:修改 代码 删除项目 确认 何修改      更新时间:2023-09-26

我的代码使删除项目之前我确认它。我怎么做更改,让它删除项目后,我确认它。下面是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();
    }

这个问题的答案包含了一个完整的解决方案,使用jquery-ui对话框作为弹出确认对话框。

你想在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.
    }
    

结果是你现有的删除按钮只是揭示了删除按钮,实际执行回调,现在包含在确认弹出。

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

这回答了你的问题吗?

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