用户不会看到JQuery模式对话框确认

时间:2016-01-14 15:53:42

标签: javascript c# jquery asp.net

我正在开发一个基于ASP.NET的WebForms应用程序,并用C#编码。此应用程序执行CRUD操作,每次用户想要执行操作时,我都需要向客户端显示确认消息。我决定创建一个jQuery函数,它接收窗口的标题,显示给用户的消息以及代表该动作的按钮。

这是我的Javascript功能:

var _confirm = false;
function Confirm(str, strtitle,button) {
  e.preventDefault();
  if (!strtitle) strtitle = 'Mensaje de error';
  $('#dialog').show();
  $('#dialog').html(str);

  $("#dialog").dialog({
    autoOpen: true,
    draggable: false,
    resizable: false,
    modal: true,
    title: strtitle,
    width: 350,
    height: 180,
    show: "slide",
    hide: "puff",

    buttons: {
      "No": function () {
        jQuery(this).dialog("close");
      },

      "Yes": function () {
        jQuery(this).dialog("close");
        _confirm = true;
        button.click();
      }
    },

    close: function () {
      jQuery(this).remove();
    }
  });
  return false;
}

这是ASP按钮:

<asp:button id="btnOk" onclick="btnDGV_Click" 
            onclientclick="Confirm('Desea eliminar el registro', 'Confirmacion', this);" 
            runat="server" text="Eliminar Registro">
</asp:button>

事件的代码在服务器端onclick(暂时只是一条确认消息):

protected void btnDGV_Click(object sender, EventArgs e) {
  ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Registro eliminado exitosamente !!!')", true);
}

问题在于,当我单击按钮时,始终会显示服务器端消息,并且永远不会显示jQuery对话框。可能是什么问题?

2 个答案:

答案 0 :(得分:1)

修改你的代码: onclientclick="Confirm('Desea eliminar el registro', 'Confirmacion', this);return;" 这会阻止按钮进行回发

并修改: "Yes": function () { jQuery(this).dialog("close"); __doPostBack('<%=btnOk.ClientID%>', '') button.click(); } 如果你点击&#34;是&#34;此代码进行回发并调用按钮的onclick属性上指定的方法

答案 1 :(得分:0)

以下是一些需要检查的内容:

  1. 检查asp:按钮在客户端上的呈现方式(用于您的启发)
  2. 检查您的onclientclick是否会阻止该元素发布到服务器。您可能希望在此处返回确认功能的结果。
  3. 检查确认功能的顺序。您已尝试在对话框初始化之前显示该对话框。
相关问题