0

I try to show jquery dialog by clicking the Delete button ( which also serves to erase data if the user than in the dialog ), but when I press the Delete dialog then disappears after the second and screen pops . I'd love someone to help me because I really green in jquery And how to check user code approved in dialog Thank you :)

    <script type="text/javascript">
            $(function () {
                $("#dialog-confirm").hide();
                $("#but_Delete").click(function () {
                    $("#dialog-confirm").dialog({
                        resizable: false,
                        height: 250,
                        width: 500,
                        modal: true,
                        buttons: {
                            "delete": function () {
                                $.ajax({
                                    type: "GET",
                                    contenttype: "application/json; charset=utf-8",
                                    data: "{null}",
                                    url: "Home.aspx/but_Delete_Click",
                                    dataType: "json",
                                    success: function but_Delete_Click(res) {
                                       
                                    },
                              
                                });
                                $(this).dialog("close");
                            },
                            "Cancel": function () {
                                $(this).dialog("close");
                            }
                        }


                    });

                    //$(".selector").dialog({Zz
                    //    closeOnEscape: false

                    //});
                });

            });

  </script> 
protected void but_Delete_Click()
{          
     if (TextBox_campeny.Text != null || TextBox_Addres.Text != null || TextBox_tel.Text != null)
     {                 
           con.Open();
           string id = tb.Tables[0].Rows[i]["id"].ToString();
           SqlCommand cmd = new SqlCommand("Delete from tbl_Customer where Id='" + id + "'", con);
           cmd.ExecuteNonQuery();                 
           Response.Write("blabla!");
           con.Close();
           con.Open();
           SqlCommand cmd_u = new SqlCommand("Delete from tbl_Users where IdCustomer='" + id + "'", con);
           SqlDataAdapter dac = new SqlDataAdapter(cmd_u);
           dac.Fill(tb);
           if (butuc == 1)
           {
                 Response.Redirect("LoginPage.aspx");
           }
           else
           {
                 if(tb.Tables[0].Rows.Count != 1)
                 {
                     if (i == 0)
                     {                                
                           bind();
                     }
                     else
                     {
                           if (tb.Tables[0].Rows.Count - 1 == i)
                           {
                                  i--;
                                  bind();
                           }
                           else
                           {
                                  bind();                                  
                           }
                      }
                      else
                      {
                           Empty_Textbox();
                           but_Delete.EnableTheming = false;
                      }

                  }
             }
             con.Close();
       }
}
Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200

2 Answers2

0

This deletion button when pressed appears Dialog

     <input type="button" value="Delete" id="but_Delete" name="but_Delete" runat="server" />
and this is the div of the dialog
 <div id="dialog-confirm" title="Are you sure you want to delete?">
 
0

Because of server side

  1. Remove custom dialog box, use window confirm

  2. Create new function in javascript OnClick="but_Delete_Click" OnClientClick="return somefunction();" function somefunction() { return window.confirm("Are you sure you want to delete?"); }

    1. public void but_Delete_Click(object sender, EventArgs e)

Note : 1. use update panel for use but_Delete_Click event from javascript with __doPostBack() 2. you can use web method but server side control like textbox or button not find in it you should manual passed from parameter which value use in web method

Community
  • 1
  • 1
Silence Peace
  • 341
  • 4
  • 13