В приведенном ниже коде iam выполняет функции для вставки значений в db.Everything работает нормально, но дело в том, что если я нажимаю F5 или Ctrl + F5, страница перезагружается и те же значения вставляя еще раз. Я просто опустошил значения текстового поля, но он не работает. Как предотвратить дублирование вставки.Как предотвратить дублирование вставки при нажатии F5
Спасибо заранее.
protected void btnAddNewQuestion_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("Usp_insertNewQuestion", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@AppID", SqlDbType.Int).Value = applicationId;
cmd.Parameters.Add("@TenantID", SqlDbType.Int).Value = 1;
cmd.Parameters.Add("@Questions", SqlDbType.VarChar).Value = txtNewQuestion.Text;
cmd.Parameters.Add("@QuestionType", SqlDbType.VarChar).Value = ddlNewQuestionType.Text;
cmd.Parameters.Add("@AudioPath", SqlDbType.VarChar).Value = txtNewAudioPath.Text;
cmd.Parameters.Add("@QuestionStatus", SqlDbType.Int).Value = Int32.Parse(rdoNewQuestionStatus.SelectedItem.Value);
cmd.Parameters.Add("@DataType", SqlDbType.VarChar).Value = ddlNewQuestionDataType.Text;
cmd.Parameters.Add("@UserField", SqlDbType.VarChar).Value = ddlNewUserField.Text;
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception err)
{
Response.Write(err.Message);
}
finally
{
con.Close();
}
//string type = Page.Request.Form["hdnAddQuestionField"].ToString();
// if (type == "Security Question")
// getSecurityQuestions();
//if (type == "Personal Identity")
// getPersonalIdentityQuestions();
//if (type == "Past History")
// getPastHistoryQuestions();
txtNewQuestion.Text = string.Empty;
ddlNewQuestionType.Text = string.Empty;
txtNewAudioPath.Text =string.Empty;
rdoNewQuestionStatus.SelectedItem.Value = string.Empty;
ddlNewQuestionDataType.Text = string.Empty;
ddlNewUserField.Text = string.Empty;
}
хорошо сказал @claudio Реди –