3
Guys, I have the following problem:
I have a web application made with ASP.NET and C#.
In this application I have a simple entry registration system.
After I register an item in the application, if I have the browser page updated (press F5), the browser opens a pop up asking to resend the form, consequently it generates a duplicate in the database.
This is the excerpt from the code where I register at the bank:
PgSqlConnection Myconn = new PgSqlConnection(connectionString);
query = "INSERT INTO banco(a,b,c,d,e,f) VALUES (" + a + "," + b.SelectedValue + "," + c + "," + d + "," + e +"," + f.SelectedValue + ")";
PgSqlCommand Command = new PgSqlCommand(query, Myconn);
Myconn.Open();
try
{
Command.ExecuteNonQuery();
}
catch (PgSqlException ex)
{
String myscript = "alert('Não foi possível executar esta ação')";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", myscript, true);
}
How can I stop it?
To facilitate further research, please follow below the excerpt of the code with the solution of the problem:
PgSqlConnection Myconn = new PgSqlConnection(connectionString);
query = "INSERT INTO banco(a,b,c,d,e,f) VALUES (" + a + "," + b.SelectedValue + "," + c + "," + d + "," + e +"," + f.SelectedValue + ")";
PgSqlCommand Command = new PgSqlCommand(query, Myconn);
Myconn.Open();
try
{
Command.ExecuteNonQuery();
Response.Redirect("estearquivo.aspx"); //isto soluciona o problema
}
catch (PgSqlException ex)
{
String myscript = "alert('Não foi possível executar esta ação')";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", myscript, true);
}
You have how to show the input code, including the event that calls this insert?
– Leonel Sanches da Silva
You’re checking if it’s a Postback?
– Leonel Sanches da Silva