title: Confirmation Message BOx function for asp.net?
body: <p>This is my <code>Delete</code> function after a click. Can anyone show me how to do a simple confirmation function?</p>
  
  <p>ASP.net C#.  </p>
  
  <p>Previously I had this </p>
  
  <pre><code>ScriptManager.RegisterStartupScript(this, 
         this.GetType(),
         "script",
         "confirm('Are you sure you want to Delete Your Discussion?');", 
         true);
  </code></pre>
  
  <p>but the above code run after the deletion has been made.</p>
  
  <pre><code>protected void lnk_delete_Click(object sender, EventArgs e)
  {
      GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
      string fieldID = grdrow.Cells[0].Text;
  
      string query = "Delete from Comment where DiscussionID=@id";
  
      SqlCommand cmd = new SqlCommand(query, cn);
      cmd.Parameters.AddWithValue("@id", fieldID);
  
      cn.Open();
      cmd.ExecuteNonQuery();
      cn.Close();
  
      string query1 = "Delete from Discussion where DIscussionID=@id";
  
      SqlCommand cmd1 = new SqlCommand(query1, cn);
      cmd1.Parameters.AddWithValue("@id", fieldID);
  
      cn.Open();
      cmd1.ExecuteNonQuery();
      cn.Close();
  
      GridView1.DataBind();
  }
  </code></pre>