首页 文章

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

提问于
浏览
2

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

这是我的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

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

    • 检查asp:在客户端上呈现的按钮(用于您的启发)

    • 检查您的onclientclick是否会阻止该元素发布到服务器 . 您可能希望在此处返回Confirm功能的结果 .

    • 检查确认功能的顺序 . 你're trying to show the dialog before it'已被初始化 .

  • 1

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

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

相关问题