There are 2 textbox on web Page say First Name, Last Name, etc.
And a Button called Insert Records.
On Click of Insert Button, records get inserted. After inserting the records, If you refresh the page, it will again insert records.
How can you prevent it?

Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Oct 10, 2008, 8:43 AM EDT
Hi,
You need to place Business Unique keys on the table columns to avoid this.
Thanks -- Vj
http
://dotnetvj.blogspot.comhttp
://oravj.blogspot.comNiradhip ChakrabortyRank #429 · 5.8K reputationPosted Oct 10, 2008, 1:42 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 10, 2008, 3:20 PM EDT
See Following Code Written by me
protected void btnInsert_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
Response.Write("Connection Success");
comm = new SqlCommand();
comm.Connection = con;
comm.CommandText = "INSERT INTO users VALUES('" + txtUsername.Text + "','" + txtPassword.Text + "')";
comm.ExecuteNonQuery();
con.Close();
Response.Redirect("~/default.aspx");
showdata();
}
Regards,
zafar jaffary4 reputationPosted Oct 27, 2008, 6:40 AM EDT
Hello
Did your problem solve already? I have the same problem. I have a button on my asp.net application it should insert new record if no record exist in the database otherwise update the record.
Can you help me out? if i give you my code?
Thanks
ArshadRank #2,492 · 564 reputationPosted Oct 29, 2008, 12:11 PM EDT
if(ViewState["Khan"]==null)
{
//your code for Adding the Data in your database
//after that just assign the value to the viewstate, some thing like that
ViewState["Khan"].ToString()=="Done"
}
I hope it should work, please check it n let me know.
Thanks