473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding javascript window.confirm to linkbutton

Is it possible to pre-empt the javascript function used to do a postback
from a linkbutton?

I'd like to use linkbutton to delete a record and want to add a confirmation
box via javascript "are you sure you want to delete this record?" before it
executes the postback. The javascript is straightforward for this, but have
no idea how to have that intercept the post-back script.

-Darrel

Aug 2 '07 #1
14 18224
"darrel" <no*****@nowher e.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Is it possible to pre-empt the javascript function used to do a postback
from a linkbutton?

I'd like to use linkbutton to delete a record and want to add a
confirmation box via javascript "are you sure you want to delete this
record?" before it executes the postback. The javascript is
straightforward for this, but have no idea how to have that intercept the
post-back script.
Any JavaScript function which returns false will intercept a postback e.g.

<asp:Button ID="MyButton" runat="server" OnClick="MyButt on_Click"
OnClientClick=" return confirm('Are you sure you want to delete this
record?');" Text="Delete" />

In the above example, when a user clicks on the Delete button, they will be
prompted with a client-side Yes/No alert - if they click Yes, the postback
will happen and run the code in the server-side MyButton_Click method - if
they click No, the postback will be intercepted and nothing further will
happen...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 2 '07 #2
<asp:Button ID="MyButton" runat="server" OnClick="MyButt on_Click"
OnClientClick=" return confirm('Are you sure you want to delete this
record?');" Text="Delete" />
Slick, but can this be done with a linkButton? I don't see an OnClientClick
property for that.

-Darrel
Aug 2 '07 #3
"darrel" <no*****@nowher e.comwrote in message
news:u9******** ******@TK2MSFTN GP05.phx.gbl...
><asp:Button ID="MyButton" runat="server" OnClick="MyButt on_Click"
OnClientClick= "return confirm('Are you sure you want to delete this
record?');" Text="Delete" />

Slick, but can this be done with a linkButton? I don't see an
OnClientClick property for that.
Yep - in the Page_Load, add the following code:

MyLinkButton.At tributes.Add("o nclick", "return confirm('Are you sure you
want to delete this record?');");
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 2 '07 #4
MyLinkButton.At tributes.Add("o nclick", "return confirm('Are you sure you
want to delete this record?');");
Hmm...I've done that, but the event handler still executes for the
linkButton regardless of whether I click OK or CANCEL in the confirmation
window.

-Darrel
Aug 2 '07 #5
"darrel" <no*****@nowher e.comwrote in message
news:OC******** ******@TK2MSFTN GP03.phx.gbl...
>MyLinkButton.A ttributes.Add(" onclick", "return confirm('Are you sure you
want to delete this record?');");

Hmm...I've done that, but the event handler still executes for the
linkButton regardless of whether I click OK or CANCEL in the confirmation
window.
Actually, having just tried this, <asp:LinkButton most certainly *does*
have an OnClientClick property:
http://msdn2.microsoft.com/en-us/lib...ck(vs.80).aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 2 '07 #6
"darrel" <no*****@nowher e.comwrote in message
news:Oe******** ******@TK2MSFTN GP05.phx.gbl...
Don't I still need to apply some sort of onClick event to the linkButton,
though? I'm not sure how the above script would know to intercept the
onClick event if there's nothing to trigger it.
MyLinkButton.At tributes.Add("o nclick", "return confirm('Are you sure you
want to delete this record?');");
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 3 '07 #7
"darrel" <no*****@nowher e.comwrote in message
news:ux******** ******@TK2MSFTN GP05.phx.gbl...
Well, this is where my lack of Javascript skills begins to show. ;0)

Here's the function I'm using curtesy of Collin:
Mark, your onclick event makes sense,
You can't have both...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 3 '07 #8
>Here's the function I'm using curtesy of Collin:
>Mark, your onclick event makes sense,

You can't have both...
Right. But that's kind of going back to my original problem...addin g the
confirmation on the OnClick event of the linkbutton does NOT intercept the
postback. Regardless of whether or not I click OK or CANCEL, the postback is
still executed.

-Darrel
Aug 3 '07 #9
Isn't JavaScript case-sensitive, so onclick should be onClick?

'doh! yea, good catch!

That said, I still get the 'mybutton has no properties' error.

-Darrel
Aug 3 '07 #10

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

Similar topics

5
7875
by: Phil Powell | last post by:
<script> <!-- function willProceedToPay() { var willPay = window.confirm('Vill du g' . String.fromCharCode(229) . ' till betaling?'); if (willPay) return true; return false; }
2
2358
by: Mark Pappert | last post by:
Hi, I am trying to determine whether the status bar is visible or not .. is there a method to check the state? I did a google search and found info re: window.status.visible but it returns undefined?! Has it been deprecated? Thanks for any info! Cheers!
7
11136
by: Tasha's Dad | last post by:
A description of the problem: 1) Go to a page with various settings and a timeout (forces re-login if over 10 minutes) 2) Before the timeout, make some changes to settings. 3) Press a "reset to defaults" button that uses a confirmation box to let the user know what is about to be reset (lists items). 4) Walk away while the confirm box is displayed and come back after the page timeout. 5) My screen now has the page, a confirm popup on top...
2
4950
by: Frank Oquendo | last post by:
I need to be call up a new page from a hyperlink in a DataGrid. Unfortunately, I'm not allowed to pass any querystring values so I decided to use a TemplateColumn containing a LinkButton instead of using a HyperLinkColumn. Using the LinkButton, I can set session variables that the new page will use at startup. What I can't figure out is to open a new window. Any ideas?
1
44038
by: bbcrock | last post by:
Is it possible to send attributes into this function to change the print preferences from Portrait to Landscape with IE 6.0 set as the standard browser? Right now I'm using javascript:window.print() as the command. Clients want it and I want to confirm it's not possible. If I'm using an old, deprecated process, please give me a heads-up. I'm no
1
2503
by: Doo0592 | last post by:
Hi all, Judging by the topics in here this should be a snap for all of you! Can any one explain why when i use the window.confirm in an if else statement it behaves like this: if (var == value) { do this
1
2535
by: Jack | last post by:
Hi, I am new to .NET and need help with adding click event on LinkButton programatically. Please see the code below. I would like to add a click event on LinkButton returned from "Function EditLink". This LinkButton should fire "Sub EditNav" when clicked. ======================================
4
3753
by: Arnab das | last post by:
Below is the javascript code i am using function confirmDelete() { var returnValue = window.confirm("Deleting the current page. Continue?"); return returnValue; // var returnValue = $find('mdlPopUpExt').show();
3
8667
by: fishjelly | last post by:
How to open new window through linkButton without using javacript?...
0
8413
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
8842
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
8740
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
8513
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
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5642
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();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.