By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,423 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,423 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
"Rémi" <re**@terracognita.ca> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 19 '05 #2

P: n/a
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.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"Rémi" wrote:
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.

Nov 19 '05 #3

P: n/a
So, what? Returning false during client-side event handling essentially
cancels an event? Is this always true?

Remi.

Nov 19 '05 #4

P: n/a
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
"Rémi" <re**@terracognita.ca> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
So, what? Returning false during client-side event handling essentially
cancels an event? Is this always true?

Remi.

Nov 19 '05 #5

P: n/a

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

Regards,
Remi.

Nov 19 '05 #6

P: n/a
Joe
It's also true for hyperlinks. Returning false prevents the page from
navigating to the linked page.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
"S. Justin Gengo" wrote:
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
"Rémi" <re**@terracognita.ca> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
So, what? Returning false during client-side event handling essentially
cancels an event? Is this always true?

Remi.


Nov 19 '05 #7

P: n/a
Remi,

You're welcome.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Rémi" <re**@terracognita.ca> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...

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

Regards,
Remi.

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.