Hello.
I have just gotten a client-side delete confirmation Javascript button
to work, using this FAQ question as a basis (3rd question down, URL
<http://www.wintellect.com/resources/faqs/default.aspx?faq_id=1&page=5>.
I've no trouble with how this all works, but there's one thing I don't
quite get. In the DataGrid's ItemCreated event, I attach a small bit of
Javascript code to the onClick attribute, via the button's Attributes
collection, as so:
WebControl button = (WebControl) e.Item.Cells[0].Controls[0];
button.Attributes.Add ("onclick", "return confirm (\"Are you
sure?\");");
I understand what this is doing I also handle the DataGrid's Delete
event on the server, in page-behind code. I'm also fine with that.
What I don't get is why my server-side DataGrid Delete event handler is
not called if the onClick Javascript returns false. How and why is this
link made? I'm glad I've got something that works, but I'd much rather
understand *why* it works.
I've looked up the WebControl Attributes property, the Button's clicked
event, and a few MSDN articles that discusses consuming events, but
haven't found any info on this. What gives?
Regards,
Remi.
S. Justin Gengo - 26 Oct 2005 20:17 GMT
Remi,
The javascript returning false keeps the page from posting back at all. It's
as if the user never clicked the button at all.

Signature
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
> Hello.
> I have just gotten a client-side delete confirmation Javascript button
[quoted text clipped - 24 lines]
> Regards,
> Remi.
Rémi - 26 Oct 2005 20:25 GMT
So, what? Returning false during client-side event handling essentially
cancels an event? Is this always true?
Remi.
S. Justin Gengo - 26 Oct 2005 20:37 GMT
It's true of button clicks. I know it's also true of some other post back
events but I don't have a comrehensive list.

Signature
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
> So, what? Returning false during client-side event handling essentially
> cancels an event? Is this always true?
>
> Remi.
Rémi - 26 Oct 2005 20:51 GMT
Thanks, Justin and Curt.
That clears things up for me.
Regards,
Remi.
S. Justin Gengo - 26 Oct 2005 21:46 GMT
Remi,
You're welcome.

Signature
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
>
> Thanks, Justin and Curt.
> That clears things up for me.
>
> Regards,
> Remi.
Joe - 26 Oct 2005 20:58 GMT
It's also true for hyperlinks. Returning false prevents the page from
navigating to the linked page.

Signature
Joe
VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
> It's true of button clicks. I know it's also true of some other post back
> events but I don't have a comrehensive list.
[quoted text clipped - 3 lines]
> >
> > Remi.
Curt_C [MVP] - 26 Oct 2005 20:20 GMT
IIRC it's because the server event is waiting for the trigger. The clientside
event happens FIRST and when you click the cancel/no it returns a "false"
which stops the processing. The page never gets the post command.

Signature
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
> Hello.
> I have just gotten a client-side delete confirmation Javascript button
[quoted text clipped - 24 lines]
> Regards,
> Remi.