Foros del Web » Programando para Internet » ASPX (.net) »

Evitar Insert cuando hacen refresh F5

Estas en el tema de Evitar Insert cuando hacen refresh F5 en el foro de ASPX (.net) en Foros del Web. Estimados un saludo cordial, Sencillo (creo) pero no se como hacerlo...Tengo un form que hace un insert a una BD SQL server y todo va ...
  #1 (permalink)  
Antiguo 20/09/2010, 20:12
Avatar de jpogsistem  
Fecha de Ingreso: diciembre-2001
Mensajes: 2.405
Antigüedad: 22 años, 4 meses
Puntos: 4
Evitar Insert cuando hacen refresh F5

Estimados un saludo cordial,

Sencillo (creo) pero no se como hacerlo...Tengo un form que hace un insert a una BD SQL server y todo va ok.

Pero si luego hacer el submit (y mientras este es procesado) el usuario hace refresh en el navegador u oprime F5, sale el mensajito de si se desean enviar de nuevo los datos del navegador...............y a mis usuarios al parecer les fascina esto y queda la info repetida.

Saben como solucionarlo ? estoy en VB.net.

Muchas Gracias.
__________________
EL LIMITE ES EL UNIVERSO
  #2 (permalink)  
Antiguo 21/09/2010, 06:10
Avatar de jaullo  
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: Evitar Insert cuando hacen refresh F5

En donde estas enviando el insert? trata de controlarlo con un postback, por ejemplo

Código ASP:
Ver original
  1. If not page.ispostback
  2. 'myinsert
  3. end if
__________________
http://geekswithblogs.net/jaullo/Default.aspx
Si te he ayudado regalame Karma positivo!!!
  #3 (permalink)  
Antiguo 21/09/2010, 07:03
 
Fecha de Ingreso: mayo-2008
Mensajes: 353
Antigüedad: 16 años
Puntos: 3
De acuerdo Respuesta: Evitar Insert cuando hacen refresh F5

A mi me sucedió lo mismo al usuario no le puedes amarrar las manos.
aquí lo que hice

Imports System.Web.SessionState

Private IsPageRefresh As [Boolean] = False

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim SourceTextBox As TextBox
SourceTextBox = CType(PreviousPage.FindControl("txtuser"), _
TextBox)
If Not SourceTextBox Is Nothing Then

Session("update") = Server.UrlEncode(System.DateTime.Now.ToString())


' esto es para controlar el F5
ViewState("postids") = System.Guid.NewGuid().ToString()
Session("postid") = ViewState("postids").ToString()

Else
If ViewState("postids").ToString() <> Session("postid").ToString() Then
IsPageRefresh = True
End If
Session("postid") = System.Guid.NewGuid().ToString()
ViewState("postids") = Session("postid")

End If
End If
End Sub


luego donde tienes proceso para actualizar va esto

If Not IsPageRefresh Then
If ddlpais.SelectedItem.Value = "Select" Or ddlregion.SelectedItem.Value = "Select" Or ddlclte.SelectedItem.Value = "Select" Or txtnrosini.Text = "" Then
alert("Pais o Region o Cliente o Nro. Siniestro NO correctos")
Exit Sub
End If

If txtcosto.Text <> "" Then
txtcosto.Text = Replace(txtcosto.Text, ",", ".")
Else
txtcosto.Text = "0"
End If

If txtventa.Text <> "" Then
txtventa.Text = Replace(txtventa.Text, ",", ".")
Else
txtventa.Text = "0"
End If

If txtflete.Text <> "" Then
txtflete.Text = Replace(txtflete.Text, ",", ".")
Else
txtflete.Text = "0"
End If

If txtcant.Text = "" Then
txtcant.Text = "0"
End If

txtpart.Text = ""
txtdescrparte.Text = ""
txtcosto.Text = ""
txtflete.Text = ""
txtventa.Text = ""
txtcant.Text = ""
FillCustomerInGrid()
Else
'esto es por que cuando le dan F5 no borra los datos y hay que borrarlo de nuevo
txtpart.Text = ""
txtdescrparte.Text = ""
txtcosto.Text = ""
txtflete.Text = ""
txtventa.Text = ""
txtcant.Text = ""
FillCustomerInGrid()
End If

suerte

Etiquetas: cuando, insert, refresh, aspx
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:57.