Home All Groups Group Topic Archive Search About

OnClientClick with confirm doesn't work

Author
8 Jan 2009 2:00 PM
Mauricio Pires
My GridView has a button with OnClientClick="if (!confirm('Delete?')) return
false;" which must deletes a record only if the user click on the OK button
of the confirmation window, but if he clicks on the Cancel button the record
is also deleted, that is, it is not working.

Could someone help me?

Author
12 Jan 2009 3:14 PM
Jester98x
On 8 Jan, 14:00, Mauricio Pires
<MauricioPi***@discussions.microsoft.com> wrote:
> My GridView has a button with OnClientClick="if (!confirm('Delete?')) return
> false;" which must deletes a record only if the user click on the OK button
> of the confirmation window, but if he clicks on the Cancel button the record
> is also deleted, that is, it is not working.
>
> Could someone help me?

Hi Mauricio,

Had same problem myself some time ago.

Solution was to use OnClientClick="return confirm('Delete?');"

Hope this helps.
Steve
Are all your drivers up to date? click for free checkup

Author
14 Jan 2009 2:32 AM
rstrahl
You need to also set the Submit behavior I think. If you leave it at default
a Submit button is generated which will always submit. If you use
UseSubmitBehavior == false the button gets generated as a button in which
case you can control submission manually:

<asp:Button runat="server" id="myButton" UseSubmitBehavior="False"
              OnClientClient="if (!confirm("Delete?") return;
window.forms[0].submit();" />

+++ Rick ---
--
Rick Strahl
West Wind Technologies
www.west-wind.com/weblog



Show quoteHide quote
"Mauricio Pires" <MauricioPi***@discussions.microsoft.com> wrote in message
news:F0F4070E-7E4E-4B30-803F-6DE295603050@microsoft.com...
> My GridView has a button with OnClientClick="if (!confirm('Delete?'))
> return
> false;" which must deletes a record only if the user click on the OK
> button
> of the confirmation window, but if he clicks on the Cancel button the
> record
> is also deleted, that is, it is not working.
>
> Could someone help me?
>
>
Author
21 Jan 2009 8:24 AM
Jester98x
rstrahl,

You don't need to use the UseSubmitBehavior in this instance as the
OnClientClick="return confirm('Delete?');"  will return false if the
user selects No on the confirmation box, which in turn blocks the
button click event from bubbling any further.  i.e. stopping the form
submission.  OnClientClick="return confirm('Delete?');"  is basically
a shorthand version of your code.

Steve

Show quoteHide quote
On Jan 14, 2:32 am, "rstrahl" <rickstr***@hotmail.com> wrote:
> You need to also set the Submit behavior I think. If you leave it at default
> a Submit button is generated which will always submit. If you use
> UseSubmitBehavior == false the button gets generated as a button in which
> case you can control submission manually:
>
> <asp:Button runat="server" id="myButton" UseSubmitBehavior="False"
>               OnClientClient="if (!confirm("Delete?") return;
> window.forms[0].submit();" />
>
> +++ Rick ---
> --
> Rick Strahl
> West Wind Technologieswww.west-wind.com/weblog
>
> "Mauricio Pires" <MauricioPi***@discussions.microsoft.com> wrote in message
>
> news:F0F4070E-7E4E-4B30-803F-6DE295603050@microsoft.com...
>
> > My GridView has a button with OnClientClick="if (!confirm('Delete?'))
> > return
> > false;" which must deletes a record only if the user click on the OK
> > button
> > of the confirmation window, but if he clicks on the Cancel button the
> > record
> > is also deleted, that is, it is not working.
>
> > Could someone help me?

Bookmark and Share