473,837 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Elegant Way to Handle "Are you Sure" Dialog on Client

Let's say I have a web forms button which performs a Delete or something. I'd
like a click on the button to pop an "Are you Sure" dialog on the client side
and then only execute the button's OnClick operation on the server side if
the user had clicked Ok (as opposed to Cancel) on the pop-up dialog.

I know I can do this all myself with JavaScript, but I was just wondering if
any such functionality is already built-in in ASP.NET 2.0 so that the Button
control actually renders the necessary client-side scripting by itself.

Alex
Apr 30 '06 #1
6 7211
Hi,

using OnClientClick attribute of Button

OnClientClick=" if(!confirm('Ar e you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:DB******** *************** ***********@mic rosoft.com...
Let's say I have a web forms button which performs a Delete or something.
I'd
like a click on the button to pop an "Are you Sure" dialog on the client
side
and then only execute the button's OnClick operation on the server side if
the user had clicked Ok (as opposed to Cancel) on the pop-up dialog.

I know I can do this all myself with JavaScript, but I was just wondering
if
any such functionality is already built-in in ASP.NET 2.0 so that the
Button
control actually renders the necessary client-side scripting by itself.

Alex

Apr 30 '06 #2
Oooh! I didn't know about this OnClientClick thing. That's pretty cool. But
I'm not sure I understand your code here. When you do a "return false" or a
"return true" inside the OnClientClick, what effect will that end up having?
Does "return true" result in the Button's server-side "OnClick" function
getting called and the "return false" does not? Is that what happens?

Alex
"Teemu Keiski" wrote:
Hi,

using OnClientClick attribute of Button

OnClientClick=" if(!confirm('Ar e you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:DB******** *************** ***********@mic rosoft.com...
Let's say I have a web forms button which performs a Delete or something.
I'd
like a click on the button to pop an "Are you Sure" dialog on the client
side
and then only execute the button's OnClick operation on the server side if
the user had clicked Ok (as opposed to Cancel) on the pop-up dialog.

I know I can do this all myself with JavaScript, but I was just wondering
if
any such functionality is already built-in in ASP.NET 2.0 so that the
Button
control actually renders the necessary client-side scripting by itself.

Alex


Apr 30 '06 #3
Also, an <ASP:Button /> doesn't seem to have an OnClientClick property. Is it
officially supported?

Alex

"Teemu Keiski" wrote:
Hi,

using OnClientClick attribute of Button

OnClientClick=" if(!confirm('Ar e you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:DB******** *************** ***********@mic rosoft.com...
Let's say I have a web forms button which performs a Delete or something.
I'd
like a click on the button to pop an "Are you Sure" dialog on the client
side
and then only execute the button's OnClick operation on the server side if
the user had clicked Ok (as opposed to Cancel) on the pop-up dialog.

I know I can do this all myself with JavaScript, but I was just wondering
if
any such functionality is already built-in in ASP.NET 2.0 so that the
Button
control actually renders the necessary client-side scripting by itself.

Alex


Apr 30 '06 #4
Oops! I was wrong. Never mind!

"Alex Maghen" wrote:
Also, an <ASP:Button /> doesn't seem to have an OnClientClick property. Is it
officially supported?

Alex

"Teemu Keiski" wrote:
Hi,

using OnClientClick attribute of Button

OnClientClick=" if(!confirm('Ar e you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:DB******** *************** ***********@mic rosoft.com...
Let's say I have a web forms button which performs a Delete or something.
I'd
like a click on the button to pop an "Are you Sure" dialog on the client
side
and then only execute the button's OnClick operation on the server side if
the user had clicked Ok (as opposed to Cancel) on the pop-up dialog.

I know I can do this all myself with JavaScript, but I was just wondering
if
any such functionality is already built-in in ASP.NET 2.0 so that the
Button
control actually renders the necessary client-side scripting by itself.

Alex


Apr 30 '06 #5
Yes,

"return false;" cancels the postback. Bit related discussion in my blog:
http://aspadvice.com/blogs/joteke/ar.../30/17118.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:B0******** *************** ***********@mic rosoft.com...
Oooh! I didn't know about this OnClientClick thing. That's pretty cool.
But
I'm not sure I understand your code here. When you do a "return false" or
a
"return true" inside the OnClientClick, what effect will that end up
having?
Does "return true" result in the Button's server-side "OnClick" function
getting called and the "return false" does not? Is that what happens?

Alex
"Teemu Keiski" wrote:
Hi,

using OnClientClick attribute of Button

OnClientClick=" if(!confirm('Ar e you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:DB******** *************** ***********@mic rosoft.com...
> Let's say I have a web forms button which performs a Delete or
> something.
> I'd
> like a click on the button to pop an "Are you Sure" dialog on the
> client
> side
> and then only execute the button's OnClick operation on the server side
> if
> the user had clicked Ok (as opposed to Cancel) on the pop-up dialog.
>
> I know I can do this all myself with JavaScript, but I was just
> wondering
> if
> any such functionality is already built-in in ASP.NET 2.0 so that the
> Button
> control actually renders the necessary client-side scripting by itself.
>
> Alex


Apr 30 '06 #6
Thanks for Teemu's good suggestion.

Hi Alex,

The "OnClientCl ick" is a new property added in the .net framework 2.0. And
in 1.x, we may need to use codebehind code to programmaticall y register
such script. e.g:

Button1.Attribu tes["onclick"] = "if(!confirm('A re you sure?')){return
false};";

And as for the following script:

if(!confirm('Ar e you sure?'))return false;

you can just expand it to make it looks clearer:
if(!confirm('Ar e you sure?'))
{
return false;
}

that means if the user click "No" for the confirm javascript dialog, the
code block return false. And return false in client-script event handler
means cancel the current event processing, and for your submit button, it
means stop the postback to server.

Here are some additional web artcles on client script event handling:

#Confirm Delete - Javascript
http://davidhayden.com/blog/dave/arc...03/16/178.aspx

#Advanced JavaScript Event Handling
http://www.webdevelopersjournal.com/...jsevents2.html
Hope this also helps.

Regards,

Steven Cheng
Microsoft Online Community Support
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
May 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2241
by: asj | last post by:
luke: BORRRRRRRRING......the most interesting initiatives are happening on the client side - in small wireless devices such as cellphones and smartphones, where J2ME has become the de facto standard for application development. Article from Javaworld.com: "Java everywhere is for world domination" http://www.javaworld.com/javaworld/jw-08-2003/jw-0822-wireless.html? Some quotes:
1
1438
by: Jerry J | last post by:
I'm trying to understand how many threads are involved when a client event handler is called. I am using a simple .net windows application. I click a button on a form that triggers an event. The event delegate calls two event handlers in two seperate object instances. Are the event handlers getting called sequentially relative to the main thread or are seperate threads being generated to handle the events?
7
3557
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout way to do this in 3 steps: 1. Add in main_file.cpp
10
2338
by: Generic Usenet Account | last post by:
I have worked out a very simple method for tracking the "memory growth" of a process at run time. It involves a header file and a shell script. Here's the header file: ////////// Header File Begin /////////////// #ifndef _VIRTMEMINFO_H_ #define _VIRTMEMINFO_H_ #include <stdio.h>
1
1307
by: sitpost | last post by:
Now it a matter of days before the election, and the battleground-states are living up to thier names! Both candidates are "running neck-and-neck" -- a tie-breaker may be a vote for the third--party, 'NO NOT NADER' Michael Badnarik as an alternative to Bush-- Liberatrian Party (Listed as OTHER Party in OHIO) www.badnarik.org. If this third-party gets five percent of the popular vote nationwide, it will receive federal support; not to...
4
7025
by: Patrick | last post by:
I'm writing a winforms database application in C#. I've come across a lot of stuff lately about "N-Tier" architecture. Can anyone give me a simple explanation of N-Tier? The descriptions that I've found online are chock full of lingo that I simply don't know. I need the "N-Tier" for Dummies description. Talk to me like I'm in kindergarten. Of course, I'm particularly interested in how N-Tier relates to creating a winforms database...
1
2121
by: ComputerGuyCJ | last post by:
I have an application that I've used click-once deployment to publish out to a shared network path. From there I installed the app on a few client machines, including my own. Since then I published a few updates that were recognized by the app, and the users installed them, so everyone's on the most current version. A couple of glitches are now showing up. 1. One of my users received a prompt when she opened up the app that there is a...
2
7405
by: lazypig06 | last post by:
Hi ! Yesterday, I posted a topic regarding to XML problem that I've been having. The old topic can be found at: http://groups.google.com/group/comp.lang.php/browse_thread/thread/401e2b5cb251c21/8a0eeb03626018f4?lnk=st&q=lazypig06%40gmail.com&rnum=1&hl=en#8a0eeb03626018f4 Thanks to Álvaro G. Vicario for pointing out "chunked" transfer thing. Anyway, I tried to avoid "chunked" transfer in HTTP protocol. I have looked at...
2
1297
by: amievil | last post by:
wow... I think I'm in a trouble now. My boss is a web programmer. She said, the client asked her to develop a " dot net C" application. So, she bought Microsoft visualstudio .NET 2003 and managed to develop a " DOT NET " application. What she did is, in the Microsoft visualstudio .NET 2003, made a new MFC project,
5
6229
by: Stefano Tonello | last post by:
Hi all, I need to call windows' "open with" dialog from my C# windows form application. After the user selects application, control must return to me (I have to launch directly the process). I found this solution: http://www.codeproject.com/KB/shell/openwith.aspx but it's not good for me since it will execute the process directly.
0
9839
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10564
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10621
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9396
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6998
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.