473,386 Members | 1,766 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,386 software developers and data experts.

do JS 'Confirm' for Button web control

On my page I have a 'Delete Record' web control (with code behind). How can
I issue a JS confirm('Are you sure you want to delete?') and cancel the
postback (and button event) if the user clicks 'No'?

I know I can do
myBtn.Attributes.Add("onclick", "confirm('are you sure..')") but how can
I cancel it?

Thanks,

Paul.
Nov 18 '05 #1
3 2098
myBtn.Attributes.Add("onclick", "return confirm('are you sure..')")

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Paul W" <qq*@qqq.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
On my page I have a 'Delete Record' web control (with code behind). How can I issue a JS confirm('Are you sure you want to delete?') and cancel the
postback (and button event) if the user clicks 'No'?

I know I can do
myBtn.Attributes.Add("onclick", "confirm('are you sure..')") but how can I cancel it?

Thanks,

Paul.

Nov 18 '05 #2
Metabuilders has a free server control that handles this:
http://www.metabuilders.com/Tools/ConfirmedButtons.aspx

It allows you to set the confirmation as a property, checks if browser
supports Javascript, etc. It also works in a datagrid.
- Jon
http://weblogs.asp.net/jgalloway

Nov 18 '05 #3
Here's some server side code that outputs javascript similar to what you are
requesting:
myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Paul W" <qq*@qqq.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
On my page I have a 'Delete Record' web control (with code behind). How
can I issue a JS confirm('Are you sure you want to delete?') and cancel
the postback (and button event) if the user clicks 'No'?

I know I can do
myBtn.Attributes.Add("onclick", "confirm('are you sure..')") but how
can I cancel it?

Thanks,

Paul.

Nov 18 '05 #4

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

Similar topics

5
by: Logger | last post by:
Help, I’m trying to implement a confirm button on an asp.net page. I have it attached to a asp:button control. In the button1 click event I call the CreateConfirmBox subroutine. The Box comes...
3
by: Doug O'Leary | last post by:
Hey, all; Apparently, I'm missing the concept. I'm writing a web app in perl to manage nagios configuration files. One of the things I'd like to do is to confirm an update via a popup window...
10
by: Mike Malter | last post by:
I have scoured the web looking for an example of how to do a javascript confirm box in .NET. Is there any way to do it? Thanks.
1
by: Sandy | last post by:
I have a repeater which shows Group names. (Skip this part if you want rather irrelevant) The groups are ordered and formatted: Parent ---Child ------Grand Child (okay start reading again...
13
by: Chris | last post by:
I can create Javascript confirm message boxes during page creation, etc adding them to the button attributes (many good posts on this!). But how can I add this event after the button is pressed? I...
3
by: ad | last post by:
I want user can confirm before delete records ? How can I show a confirm dialog when users press a button?
5
by: rodchar | last post by:
hey all, in my page load i'm attaching a javascript confirm message to my save button. my problem is i have some client side validation which uses a Custom Validator web control and when i make...
5
by: Dave | last post by:
I'm tearing my hair out over this one. Using VS 2003, inline (not code-behind), vb.net. I have a button (btnClear) that calls a vb routine that goes into sql server and truncates a table. ...
8
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.