How to stop an event firing in Client Side Scripting

  • Thread starter Thread starter Jorge Luzarraga C
  • Start date Start date
J

Jorge Luzarraga C

Hello,

I have a Web Form which has two imagebuttons (Save and Cancel). I´d like to
show the user a confirm dialog whenever he clicks on the Cancel Button and
based on his answer to this confirmation continue with the postback or
cancel the action.

How could I do that?

Whenever the user clicks on the cancel buttton I get the dialog but no
matter what answer the user gives I still get a postback.


btnCancelar.Attributes.Add("onclick","event.cancelBubble = !confirm('¿Desea
Cancelar la Edición de la Prima?');");





TIA,



Jorge Luzarraga
 
btnCancelar.Attributes.Add("onclick","return !confirm('¿Desea Cancelar la
Edición de la Prima?');");


-- bruce (sqlwork.com)
 
Jorge,

If you don't want a postback, why are you using imagebutton webcontrol? Use
html <img ..> instead.

Eliyahu
 
Thanks for the Help, Bruce.

Actually the solution you proposed was one.

btnCancelar.Attributes.Add("onclick","return confirm('¿Desea Cancelar la
Edición de la Prima?');");

I also learned (after digging a while in the msdn.com website) that I could
inherit the ImageButton to get the behaviour I was looking for so I would
get a ConfirmImageButton.

I´ve attached the link to that article which seems interesting.

http://msdn.microsoft.com/library/d...-us/dnaspp/html/aspnet-injectclientsidesc.asp
 
Because I wanted a deterministic postback depending on the confirm dialog.
Anyway I got the solution. Thanks for your help anyway.
 
Back
Top