【问题标题】:How to modify the code to delete item after I confirm?确认后如何修改删除项目的代码?
【发布时间】:2015-08-16 19:12:03
【问题描述】:

在我确认之前,我的代码会删除项目。确认后如何进行更改以使其删除项目。这是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();
    }

我将不胜感激。

【问题讨论】:

    标签: javascript c# confirm


    【解决方案1】:

    This answer to a question I asked myself 包含一个完整的解决方案,它使用 jquery-ui 对话框作为弹出确认对话框。

    您可以将其调整为您正在使用的任何 javascript 库。

    【讨论】:

      【解决方案2】:

      您可能想在 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 中随心所欲地对其进行样式化并将其隐藏(通过使其显示:无,或在屏幕外有边距。

        <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.
        }
        

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

      当然有更干净的方法可以做到这一点,但您似乎正在寻找一种快速简便的解决方案。

      这回答了你的问题?

      【讨论】:

      • 嗨。感谢您的答复。它可以工作,但会提供与我的网站风格不同的浏览器窗口。比如窗口的标题、颜色、大小。我该如何解决?
      • 我建议在代码中的某处创建一个DIV 用于确认面板,这样您就可以像使用任何其他 HTML 元素一样使用 CSS 对其进行样式化。只需更改该行以显示弹出窗口并获得用户响应。
      【解决方案3】:
      function btnChild_Delete_Click() {
          if (!confirm('Are you sure you want to delete?')) return;
          this._popup.hide();
          __doPostBack(this._source.name, '');
      }   
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-14
        • 1970-01-01
        相关资源
        最近更新 更多