DataGrid client-side confirm delete window - why does this work?

  • Thread starter =?iso-8859-1?B?UultaQ==?=
  • Start date
?

=?iso-8859-1?B?UultaQ==?=

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

S. Justin Gengo

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.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

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.
 
?

=?iso-8859-1?B?UultaQ==?=

So, what? Returning false during client-side event handling essentially
cancels an event? Is this always true?

Remi.
 
S

S. Justin Gengo

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.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
?

=?iso-8859-1?B?UultaQ==?=

Thanks, Justin and Curt.
That clears things up for me.

Regards,
Remi.
 
G

Guest

It's also true for hyperlinks. Returning false prevents the page from
navigating to the linked page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top