Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rémi - 26 Oct 2005 20:02 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.