Foros del Web » Programación para mayores de 30 ;) » .NET »

Evitar el doble clic en web controls!!!

Estas en el tema de Evitar el doble clic en web controls!!! en el foro de .NET en Foros del Web. hola gente!!! tengo que evita que la persona realice dos clic seguidos en un boton de submit, alguien sabe como hacerlo? lo que tengo es ...
  #1 (permalink)  
Antiguo 11/07/2006, 07:23
 
Fecha de Ingreso: enero-2005
Mensajes: 89
Antigüedad: 19 años, 3 meses
Puntos: 0
Exclamación Evitar el doble clic en web controls!!!

hola gente!!!

tengo que evita que la persona realice dos clic seguidos en un boton de submit, alguien sabe como hacerlo?

lo que tengo es lo siguiente:


Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<script LANGUAGE="JavaScript">
 function enviado() { 
  document.forms[0].enviar.disabled=true;
  document.forms[0].submit();
  }
</script>
<body>
<form action="http://www.yahoo.com" method="POST" name="formulario" id="formulario">
  <input name="enviar" type="submit" id="enviar" value="Enviar"  onClick="return enviado();">
</form>
</body>
</html>
este codigo html anda perfecto, pero cuando lo paso a asp .net no logro que funcione!
para pasarlo a asp .net lo que hago es agregar el atributo al boton de esta forma en el page_load()

enviar.Attributes("onclick") = "javascript: enviado();"

esto agrega la llamada al script, pero no funciona!!
lo que hice fue probar colocar el codigo del boton html comun y al lado el que genera asp .net. el primero anda el segundo no, cuando al primero le agrego "language="javascript"" que es uno de los atributos que le coloca asp .net al generar el codigo del boton el boton que antes andaba al tener este atributo ya no anda, podrian ayudarme???
alguien sabe otra posible forma de hacerlo?

Gracias!!!!
__________________
Diegote ::.

www.mmsolutions.com.ar
  #2 (permalink)  
Antiguo 11/07/2006, 08:41
Avatar de moNTeZIon  
Fecha de Ingreso: enero-2005
Ubicación: Lliçà de Munt - BCN
Mensajes: 1.625
Antigüedad: 19 años, 4 meses
Puntos: 9
Hola diegodlf,
de todos modos, lo que traduces a .Net no parece ser "lo mismo" que tienes arriba.
Me refiero a que para querer acercarse a lo de arriba, sería con el return también, igual que pusiste..

enviar.Attributes("onclick") = "javascript: return enviado();"

Es algo que vi al mirar en tu codigo, no se si te va a funcionar tampoco...
Saludos.
__________________
..:: moNTeZIon ::..
  #3 (permalink)  
Antiguo 11/07/2006, 13:15
 
Fecha de Ingreso: enero-2005
Mensajes: 89
Antigüedad: 19 años, 3 meses
Puntos: 0
hice varias pruebas, voy a probar, pero no creo que sea eso!
gracias igual!
__________________
Diegote ::.

www.mmsolutions.com.ar
  #4 (permalink)  
Antiguo 06/08/2007, 22:36
 
Fecha de Ingreso: febrero-2006
Mensajes: 155
Antigüedad: 18 años, 3 meses
Puntos: 0
Re: Evitar el doble clic en web controls!!!

Tengo el mismo problema
Pero si aplico un evento OnClick procesa antes de verificar los controles de validación, por ejemplo, si dejamos un campo vacio el boton se deshabilita de todas maneras por que el click ya esta hecho, cuando deberia deshabilitarse al enviar, al momento de hacer el post
Saludos
  #5 (permalink)  
Antiguo 11/09/2007, 11:44
 
Fecha de Ingreso: septiembre-2007
Mensajes: 2
Antigüedad: 16 años, 7 meses
Puntos: 0
De acuerdo Re: Evitar el doble clic en web controls!!!

BOTÓN QUE EVITA EL DOBLE CLICK.. :)
HOLA, ESTE ES UN WEB CONTROL QUE PASÉ A VB.NET DE UNO QUE TIENEN EN C# EN "EL GUILLE".. ESPERO Y LES SIRVA COMO A MI ME SIRVE PARA RESOLVER ESE PROBLEMA DEL DOBLE CLICK..


LO PRIMERO QUE DEBEN DE HACER ES AGREGAR UN PROYECTO DE BIBLIOTECA DE CONTROLES WEB..
DESPUES COPIAR ESTE CODIGO EN UNA LIBRERIA..
COMPILAN Y LISTO..

LUEGO TIENEN QUE AGREGAR ESTE CONTROL DENTRO DEL CUADRO DE HERRAMIENTAS..
DANDOLE CLICK DERECHO DENTRO Y SELECIONAR AGREGAR O QUITAR ELEMENTOS..

POSTERIORMENTE LE DAN EXAMINAR Y BUSCAN LA CARPETA /BIN DE LA RUTA DEL CONTROL..

Y AGREGAN EL CONTROL..

LUEGO LO ARRASTRAN.. LO PRUEBAN Y LISTO :)..




Imports System.ComponentModel
Imports System
Imports System.Web.UI
Imports System.Drawing
Imports System.Globalization
Imports System.Web
Imports System.Web.UI.WebControls

Namespace Buttons
<DefaultProperty("Text"), ToolboxData("<{0}:ButtonEnviar runat=server></{0}:ButtonEnviar>")> Public Class ButtonEnviar
Inherits System.Web.UI.WebControls.Button

Public _VstrTexoEnviando As String

<Bindable(True), Category("Appearance"), DefaultValue("Enviando..."), Description("enviar")> Public Shadows Property [Text]() As String
Get
Return _VstrTexoEnviando
End Get
Set(ByVal Value As String)
_VstrTexoEnviando = Value
End Set
End Property

'Public Property TextoEnviando() As String
' Get
' Return _VstrTexoEnviando
' End Get
' Set(ByVal Value As String)
' _VstrTexoEnviando = Value
' End Set
'End Property
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
'Creamos el panel donde va el botón principal
output.Write("<div id='div1_" & ID & "' style='display: inline'>")
output.AddAttribute("onclick", "Enviar_" & ID & "('" & ID & "');")
MyBase.Render(output)
output.Write("</div>")

'Creamos el panel y el botón secundario de envío
output.Write("<div id='div2_" & ID & "' style='display: none'>")
output.Write("<input disabled type=submit value='" & _VstrTexoEnviando & "' />")
output.Write("</div>")
End Sub
Private Function FuncionEnviarBoton() As String
Dim txt As String = "<script language='javascript'> "
txt &= " function Enviar_" & ID & "(id) { "
txt &= " if (typeof(Page_ClientValidate) == 'function') {"
txt &= " if (Page_ClientValidate() == true ) { "
txt &= " document.getElementById('div1_' + id).style.display = 'none'; "
txt &= " document.getElementById('div2_' + id).style.display ='inline'; "
txt &= " return true; "
txt &= " } "
txt &= " else { "
txt &= " return false; "
txt &= " } "
txt &= " } "
txt &= " else { "
txt &= " document.getElementById('div1_' + id).style.display = 'none'; "
txt &= " document.getElementById('div2_' + id).style.display = 'inline'; "
txt &= " return true; "
txt &= " }"
txt &= " }"
txt &= " </script>"

Return txt
End Function

Protected Overrides Sub onInit(ByVal e As EventArgs)
Me.Text = "Enviar"
Me.CausesValidation = False
End Sub
Protected Overrides Sub onPrerender(ByVal e As EventArgs)
'Registramos la función de envío del botón
Page.RegisterClientScriptBlock("fEnviar_" & ID, FuncionEnviarBoton())
MyBase.OnPreRender(e)
End Sub
End Class
End Namespace
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 23:12.