How to disable popup window on browser back and Forward button

I Doing simply insert operation on Aspx page with popUp on operation completed

enter image description here

Problem is that when I Navigate on this page through browser back and forward button .. this Popup Appears again on Load

here is my Insert Code

 protected void insert()
    {
        try
        {
            if (txtusername1.Text=="")
            { 
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "User Name can't Blank" + "');", true);
                txtusername1.BackColor = System.Drawing.Color.LightPink;
            }
            else if (txtpwd.Text == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Password can't Blank" + "');", true);
                txtpwd.BackColor = System.Drawing.Color.LightPink;
            }
            else
            {
                if (txtid.Text.Trim().ToString() == "")
                {

                    SqlCommand comd1 = new SqlCommand();
                    comd1.Connection=con;

                    con.Open();
                    comd1.CommandText = "INSERT INTO Professormaster(UserName,Password,Name,contactNo,Email,remark,AdminID,isSelected) " +
                        "VALUES(@UserName,@Password,@Name,@contactNo,@Email,@remark,@AdminID,@isSelected)";
                    comd1.Parameters.AddWithValue("@UserName", txtusername1.Text.Trim());
                    comd1.Parameters.AddWithValue("@Password", txtpwd.Text.Trim());
                    comd1.Parameters.AddWithValue("@Name", String.Empty);
                    comd1.Parameters.AddWithValue("@contactNo", Convert.ToInt32(txtContactNo.Text.Trim()));
                    comd1.Parameters.AddWithValue("@Email", txtxEmailID.Text.Trim());
                    comd1.Parameters.AddWithValue("@remark", txtRemark.Text.Trim());
                    comd1.Parameters.AddWithValue("@AdminID", Convert.ToInt32(Session["AdminID"]));
                    comd1.Parameters.AddWithValue("@isSelected", true);

                    comd1.ExecuteNonQuery();
                    con.Close();

                    ClearItem();
                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Insert Successfully!" + "');", true);
                    BindData();
                    ClearItem();
                }
                else
                {
                    SqlCommand comd1 = null;
                         con.Open();
                    comd1.ExecuteNonQuery();
                    con.Close();
                    ClearItem();

                    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Update Successfully!" + "');", true);
                    BindData();
                    ClearItem();
                }

            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

How can I avoid PopUp Appear on Browser Back and forward Button ??


Source: .net

Leave a Reply