473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 7184
Hi,

using OnClientClick attribute of Button

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

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@newsgroup.nospam> wrote in message
news:DB**********************************@microsof t.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('Are you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@newsgroup.nospam> wrote in message
news:DB**********************************@microsof t.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('Are you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@newsgroup.nospam> wrote in message
news:DB**********************************@microsof t.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('Are you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@newsgroup.nospam> wrote in message
news:DB**********************************@microsof t.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********@newsgroup.nospam> wrote in message
news:B0**********************************@microsof t.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('Are you sure?'))return false;"

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@newsgroup.nospam> wrote in message
news:DB**********************************@microsof t.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 "OnClientClick" is a new property added in the .net framework 2.0. And
in 1.x, we may need to use codebehind code to programmatically register
such script. e.g:

Button1.Attributes["onclick"] = "if(!confirm('Are you sure?')){return
false};";

And as for the following script:

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

you can just expand it to make it looks clearer:
if(!confirm('Are 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
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...
1
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. ...
7
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...
10
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...
1
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...
4
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...
1
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...
2
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:...
2
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...
5
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.