How to solve the problem of repeated save in this code of asp.net with C#

bcc1.aspx.csbcc1.aspx  I have the following code attached in file.
The data gets saved on save button, and the form is reset. But if the user click on back button of browser he can again click on save. How to disable that or remove this problem so that on back button the values are not stored in textboxes.
searchsanjaysharmaAsked:
Who is Participating?
 
Friman001Connect With a Mentor Commented:
This way, if a user goes back and the code executes again, it will see the data is already saved.  You could also look into a sort of Data Validation.  There is something out there that can see if the data has been change, and if it has, it will allow you to notify the users.
0
 
Friman001Commented:
Go out and check to see if the record already exists.  If it does, disable the button.  Otherwise, allow the user to click the button.  One easy way to see if the record exists is to use a Primary Key, which would increment an ID value for each record!

Ryan F
0
 
Friman001Commented:
Get at this code!

protected void btnsave_Click(object sender, EventArgs e)
    {
[b]if (record is already save and I can find the data)
{[/b]
        btnsave.Enabled = false;
        if (chkconfirm.Checked == true)
        {
            cmd = new SqlCommand("savebcc1", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = con;
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            cmd.Parameters.AddWithValue("@tsource",ddlsources.SelectedItem.Text.Trim());
            cmd.Parameters.AddWithValue("@tstate",ddlstates.SelectedItem.Text.Trim());
            cmd.Parameters.AddWithValue("@tdistrict",ddldistricts.SelectedItem.Text.Trim());
            cmd.Parameters.AddWithValue("@tvillage", ddlvillages.SelectedItem.Text.Trim());
            cmd.Parameters.AddWithValue("@tid",Convert.ToInt32(txtuin.Text.Trim()));
            cmd.Parameters.AddWithValue("@tchv_name",txtchv_name.Text.Trim());
            cmd.Parameters.AddWithValue("@tblock",txtblock.Text.Trim());
            
            cmd.Parameters.AddWithValue("@tphc_chc_name",txtphcchcname.Text.Trim());
            cmd.Parameters.AddWithValue("@tsub_centre", txtsubcentre.Text.Trim());
            cmd.Parameters.AddWithValue("@tccid",Convert.ToInt32(ddlcc.SelectedItem.Text.Trim()));  
            cmd.Parameters.AddWithValue("@tccname",txtccname.Text.Trim());
            cmd.Parameters.AddWithValue("@tmonth",txtmonth.Text.Trim());
            cmd.Parameters.AddWithValue("@tyear", txtyear.Text.Trim());
            cmd.Parameters.AddWithValue("@tdoi", txtdoi.Text.Trim());
            if(ddlinfotainmenttype.SelectedItem.Text=="Any other please specify")
            {
                cmd.Parameters.AddWithValue("@ttypeofinfotainment", txtotherinfotainment.Text.Trim());
            }
            else if(ddlinfotainmenttype.SelectedItem.Text!="Any other please specify")
            {
                cmd.Parameters.AddWithValue("@ttypeofinfotainment", ddlinfotainmenttype.SelectedItem.Text.Trim());
            }
            else
            {
                cmd.Parameters.AddWithValue("@ttypeofinfotainment", ddlinfotainmenttype.SelectedItem.Text.Trim());
            }
            if(ddlinfotainmentpoint.SelectedItem.Text.Trim()=="Any other please specify")
            {
                cmd.Parameters.AddWithValue("@tpointofinfotainment", txtpointofinfotainment.Text.Trim());
            }
            else if (ddlinfotainmentpoint.SelectedItem.Text.Trim()!="Any other please specify")
            {
                cmd.Parameters.AddWithValue("@tpointofinfotainment", ddlinfotainmentpoint.SelectedItem.Text.Trim());
            }
            else
            {
                cmd.Parameters.AddWithValue("@tpointofinfotainment", ddlinfotainmentpoint.SelectedItem.Text.Trim());
            }

            if (txtnopmale.Text == "")
            {
                cmd.Parameters.AddWithValue("@tmale", Convert.ToInt32("0"));
            }
            else if(txtnopmale.Text!="")
            {
                cmd.Parameters.AddWithValue("@tmale",txtnopmale.Text.Trim());
            }
            else
            {
                   cmd.Parameters.AddWithValue("@tmale", Convert.ToInt32("0"));
            }
            if(txtnopfemale.Text=="")
            {
            cmd.Parameters.AddWithValue("@tfemale", Convert.ToInt32("0"));
            }
            else if(txtnopfemale.Text!="")
            {
                cmd.Parameters.AddWithValue("@tfemale", Convert.ToInt32(txtnopfemale.Text.Trim()));
            }
            else
            {
                cmd.Parameters.AddWithValue("@tfemale", Convert.ToInt32("0"));
            }
            cmd.Parameters.AddWithValue("@tmcap", Convert.ToInt32(txtqtycap.Text.Trim()));
            cmd.Parameters.AddWithValue("@tmleaflet",Convert.ToInt32(txtqtyleaflet.Text.Trim()));
            if(txtmatertialothers.Text.Trim()!="")
            {
                cmd.Parameters.AddWithValue("@tmothers", txtmatertialothers.Text.Trim());
                cmd.Parameters.AddWithValue("@tqtyothers", Convert.ToInt32(txtqtyothers.Text.Trim()));
            }
            else if(txtmatertialothers.Text.Trim()=="")
            {
                cmd.Parameters.AddWithValue("@tmothers", "");
                cmd.Parameters.AddWithValue("@tqtyothers", Convert.ToInt32("0"));
            }
            else
            {
                cmd.Parameters.AddWithValue("@tmothers", "");
                cmd.Parameters.AddWithValue("@tqtyothers", Convert.ToInt32("0"));
            }
            
            





            cmd.ExecuteNonQuery();
            Response.Write("<script>alert('Record Saved Successfully')</script>");
            con.Close();
            lockall();
        }
    }
[b]}[/b]

Open in new window

0
 
searchsanjaysharmaAuthor Commented:
ok
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.