在jquery对话框弹出窗口中添加是或否确认

时间:2014-02-19 05:43:39

标签: javascript jquery

我使用jquery对话框弹出窗口在弹出窗口中显示消息,并且我已经从代码后面传递消息。现在我想要弹出窗口中的是或否确认,如果用户单击是,则只进行删除。但我不知道如何从代码背后执行。

<script type="text/javascript">
        function ShowPopup(message) {
            $(function () {
                $("#dialog").html(message);
                $("#dialog").dialog({
                    title: "jQuery Dialog Popup",
                    buttons: {
                        text: "Yes",
                        click: function () {
                            $(this).dialog('close');
                        }
                    },
                    text: "No",
                        Close: function () {
                            $(this).dialog('close');
                        }
                    },
                    modal: true
                });
            });
        };

</script>
<div id="dialog" style="display: none">
</div>
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    try
    {
       string   message = "Are you sure you  want to delete";


       Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);



        DataTable dt = GridView1.DataSource as DataTable;

        sQLcONN.Open();
        MySqlCommand objcmd = new MySqlCommand("delete   from shoppingcart where with_puja = '" + Convert.ToInt32(dt.Rows[e.RowIndex]["id"]).ToString() + "'", sQLcONN);
        objcmd.ExecuteNonQuery();
        Bindgrid();
        sQLcONN.Close();

    }
    catch (Exception ex)
    {
        Console.WriteLine("{0} Exception caught.", ex);
    }
    }

1 个答案:

答案 0 :(得分:0)

在js

的隐藏字段中设置确认值

ASP代码:

<asp:HiddenField id="ConfirmBit" runat="server" />

JAVASCRIPT代码:

<script type="text/javascript">
    $(document).ready(function() {  
      $("#dialog").hide(); 
      function ShowPopup(message) {
             $("#dialog").html(message);
             $("#dialog").show(); 
             $("#dialog").dialog({
                title: "jQuery Dialog Popup",
                buttons: {
                    "Yes": function () {
                              $('#ConfirmBit').val("YES");
                              $(this).dialog('close');
                           },
                     "No": function () {
                              $('#ConfirmBit').val("NO");
                              $(this).dialog('close');
                            }
                },
                modal: true
            });
       }
   });

现在比较后面代码中的比较位,并根据它执行进一步的操作。

背后的代码:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
  try
  {
   string   message = "Are you sure you  want to delete";


   Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);

    string cBit= ConfirmBit.Value;
    if(cBit.Equals("YES"))
    {
       DataTable dt = GridView1.DataSource as DataTable;
       sQLcONN.Open();
       MySqlCommand objcmd = new MySqlCommand("delete   from shoppingcart where with_puja = '" + Convert.ToInt32(dt.Rows[e.RowIndex]["id"]).ToString() + "'", sQLcONN);
       objcmd.ExecuteNonQuery();
       Bindgrid();
       sQLcONN.Close();
    }
 }
 catch (Exception ex)
  {
     Console.WriteLine("{0} Exception caught.", ex);
  }
}

快乐编码:)