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

Presiono F5 duplica datos

Estas en el tema de Presiono F5 duplica datos en el foro de ASPX (.net) en Foros del Web. Buenas, agrego un id=23 , pero cuando presiono F5, se duplica la informacion osea dos veces el ID 23 o tres veces el id 23, ...
  #1 (permalink)  
Antiguo 31/07/2010, 15:24
 
Fecha de Ingreso: mayo-2008
Mensajes: 353
Antigüedad: 16 años
Puntos: 3
Pregunta Presiono F5 duplica datos

Buenas, agrego un id=23 , pero cuando presiono F5, se duplica la informacion osea dos veces el ID 23 o tres veces el id 23, en el GridView. Uso DB sql server 2005 y vb.net. Alguien sabe por que ocurre esto.
Gracias
  #2 (permalink)  
Antiguo 31/07/2010, 17:01
Avatar de jaullo  
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: Presiono F5 duplica datos

Ya revisaste que el procedimiento que carga el dato no se este ejecutando nuevamente en el postback de la página, por hay debe estar el problema
__________________
http://geekswithblogs.net/jaullo/Default.aspx
Si te he ayudado regalame Karma positivo!!!
  #3 (permalink)  
Antiguo 31/07/2010, 20:12
 
Fecha de Ingreso: mayo-2008
Mensajes: 353
Antigüedad: 16 años
Puntos: 3
Respuesta: Presiono F5 duplica datos

gracias por responder, pero el detalle es el siguiente, se ingresa un dato (click al botón ingresar), limpio variables o texbox y en el gridview se ve el dato, luego de 3 minutos o menos presiono F5, y listo vuelve a ingresar el mismo dato.
NO es postback de la página. mira el codigo

Protected Sub btactua_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btactua.Click
'insert

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 txtdescrparte.Text = "" Then
alert("Descripcion de la parte esta en blanco")
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

customer.Insert(ddlpais.SelectedItem.Value, ddlregion.SelectedItem.Value, ddlclte.SelectedItem.Value, txtnrosini.Text, txtresponsable.Text, Trim(txtpart.Text), txtvin.Text, ddlmarca.SelectedItem.Value, ddlmodelo.SelectedItem.Value, ddlano.SelectedItem.Text, Convert.ToDecimal(txtventa.Text), Convert.ToDecimal(txtcosto.Text), Convert.ToDecimal(txtflete.Text), Trim(txtdescrparte.Text), txtfechaentrega.Text, txtcant.Text)
txtpart.Text = ""
txtdescrparte.Text = ""
txtcosto.Text = ""
txtflete.Text = ""
txtventa.Text = ""
txtcant.Text = ""
FillCustomerInGrid()

End Sub
Podrias explicarme que hace el F5. se que es refrescar, pero que mas
gracias man
  #4 (permalink)  
Antiguo 01/08/2010, 11:38
 
Fecha de Ingreso: mayo-2008
Mensajes: 353
Antigüedad: 16 años
Puntos: 3
Respuesta: Presiono F5 duplica datos

Ok, listo el pollo aquí la solución para quien la necesite


definir variable
Private IsPageRefresh As [Boolean] = False

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
ViewState("update") = Session("update")
End Sub

load de la pagina
If Not IsPostBack Then
Session("update") = Server.UrlEncode(System.DateTime.Now.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

luego en el boton

Protected Sub btactua_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btactua.Click

If Not IsPageRefresh Then
hago insert o whatever
Else
txtpart.Text = ""
txtdescrparte.Text = ""
FillCustomerGV() proceso para refrescar el GV
End If
end sub

Última edición por chuchufuentes; 03/08/2010 a las 08:43

Etiquetas: 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 13:38.