I have this GridView with checkbox which one can use to add and remove record from database. Now whenever you add or remove record from the database and you click on the backward arrow on the menu bar of a browser, it doesn’t go back to the previous page.
It first display or the actions you performed that is if for instance you added 2 items and removed one item via checking or unchecking the check box.
When you click on the backward button it ought to take you to the previous page which is issue.aspx immediately, instead when the click on the backward button on the menu bar of a browser, it will display all the message box in the order with which you performed the various action (whether adding or remove action), and you have to escape all the message box before the backward arrow on the menu bar of the browser will take you to the previous page.
What i want is for the backward arrow to take you to the previous page without displaying the message box of the action performed either by checking or unchecking the check box.
Please help
<script>
function ShowPopup(message) {
$("#lblMessage").html(message);
$("#dialog").dialog({
modal: true,
title: "Message Alert",
width: 350,
height: 160
});
}
</script>
protected void OnChckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow row = (GridViewRow)chk.NamingContainer;
string number = row.Cells[1].Text;
string pid ="206";
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
string acceptedCylinder = GetAcceptedCylinder(pid);
if (chk.Checked)
{
if (acceptedCylinder == "[]")
{
using (SqlCommand cmd = new SqlCommand("UPDATE issuesheet SET cylinders = @cylinders where pid='206'", con))
{
cmd.Parameters.AddWithValue("@cylinders", "['" + number.Trim() + "']");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('Record Inserted successfully.');", true);
}
else
{
List<string> cylinderNo = acceptedCylinder.Replace("[", "").Replace("]", "").Replace("'", "").Split(',').ToList();
cylinderNo.Add(number);
using (SqlCommand cmd = new SqlCommand("UPDATE issuesheet SET cylinders = @cylinders where pid='206'", con))
{
cmd.Parameters.AddWithValue("@cylinders", "['" + string.Join("','", cylinderNo.Distinct()) + "']");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('Record Updated Successfully.');", true);
}
}
else
{
if (!string.IsNullOrEmpty(acceptedCylinder))
{
List<string> cylinderNo = acceptedCylinder.Replace("[", "").Replace("]", "").Replace("'", "").Split(',').ToList();
cylinderNo.Remove(number);
using (SqlCommand cmd = new SqlCommand("UPDATE issuesheet SET cylinders = @cylinders where pid='206' ", con))
{
cmd.Parameters.AddWithValue("@cylinders", cylinderNo.Distinct().Count() > 0 ? "['" + string.Join("','", cylinderNo.Distinct()) + "']" : "[]");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('Record Deleted Successfully.');", true);
}
}
}
}