locked
back button RRS feed

  • Question

  • Hi,

    I'm working on a C# application where the user can submit a request form and I'm trying to avoid duplicate entries in my database. the issue is when the user submits the form and then presses the back button and submits again a duplicate entry is entered in the database. I'm using Response.Redirect to another page when the form gets submitted but that doesn't prevent it from pressing the back button and resubmitting. This is my code.
    protected void Button1_Click1(object sender, EventArgs e)
            {
               
                SqlConnection conn = new SqlConnection();//This line creates a connection called conn
                conn.ConnectionString =
                    "Data Source=TMP-DK-C10457\\SQLEXPRESS;Initial Catalog=TD;Integrated Security=True"; //connection String
    
                SqlCommand cmd = new SqlCommand();//This Line creates a new SQL COMMAND called cmd.
                cmd.CommandText =
                    "INSERT INTO PLJob(pljnumber,pljdatein,pljsubmitterid,pljgroupid,pljserviceid,pljsamplecount,pljeditcount,pljxsectionct,pljedxct,pljlotid,pljwaferct,pljparttype,pljtechnology,pljoperatorid,pljconnectsid,pljcutsid,pljknightsalign,pljtemprep,pljequipmentid,pljhours,pljdateout,pljsavings,pljreceivedid,pljcompleted,pljesthours,pljcomments,pljdelays,pljpercentsuccess,pljrootcause,pljdifficulty,pljfeedback,pljinstr) VALUES ('" + number.Text + "','" + datein.Text + "','" + submitter.Text + "','" + group.Text + "','" + service.Text + "','" + samplecount.Text + "','" + editcount.Text + "','" + xsectionct.Text + "','" + edxct.Text + "','" + lotid.Text + "','" + waferct.Text + "','" + parttype.Text + "','" + technology.Text + "','" + laboperator.Text + "','" + connects.Text + "','" + cuts.Text + "','" + knightsalign.Text + "','" + temprep.Text + "','" + equipment.Text + "','" + hours.Text + "','" + dateout.Text + "','" + savings.Text + "','" + received.Text + "','" + completed.Text + "','" + esthours.Text + "','" + comments.Text + "','" + delays.Text + "','" + percentsuccess.Text + "','" + rootcause.Text + "','" + difficulty.Text + "','" + feedback.Text + "','" + instr.Text + "')";
                // This line Sets the Command Text of cmd 
    
                cmd.Connection = conn;//This line sets the connection of cmd to conn (the connection made in the first line)
    
                conn.Open();// This opens the connection
                cmd.ExecuteNonQuery();//This executes the command (cmd)
                conn.Close();//This closes the connection
                
                Button1.Attributes.Add("onclick", "this.disabled=true;");
                
                if (Page.IsPostBack == true)
                {
                    Response.Redirect("~/default.aspx");
                }
            }
        }
    }
    • Moved by YiChun Chen Monday, December 14, 2009 11:02 AM It's off-topic here. (From:Visual C# General)
    Friday, December 11, 2009 10:55 PM

Answers


  • There is actually forum for web development questions: http://forums.asp.net/
    • Proposed as answer by JediJohn82 Friday, December 11, 2009 11:25 PM
    • Marked as answer by YiChun Chen Monday, December 14, 2009 11:02 AM
    Friday, December 11, 2009 11:25 PM