473,804 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Create a JavaScript Confirm inside a Condition in ASP.NET

Recently I needed to add a confirm to a LinkButton that called a
JavaScript function on success, and did nothing on failure. I found
documentation on adding a confirm, but not on how to place a confirm
in a conditional. In any case, I've found the answer and I thought
I'd share.

In VB.NET (in the code behind in VS.NET)

Adding just a confirm...

Dim l As LinkButton
l.Attributes.Ad d("onclick", "return confirm('Delete this item?');")

Adding a confirm inside a conditional...

Dim m As LinkButton
m.Attributes.Ad d("onclick", "if (confirm('Appro ve this item?'))
yourFunction('y ourArg') ; else return false ;")

In C# (in the code behind in VS.NET)

Adding just a confirm...

LinkButton l ;
l.Attributes.Ad d("onclick", "return confirm('Delete this item?');") ;

Adding a confirm inside a conditional...

LinkButton m ;
m.Attributes.Ad d("onclick", "if (confirm('Appro ve this item?'))
yourFunction('y ourArg') ; else return false ;") ;

(the important thing is to return a boolean = false to prevent a page
reload.)
Nov 18 '05 #1
0 1585

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

Similar topics

1
356
by: DotNetJunkies User | last post by:
I want to include javascript confirm inside the Button_Click even procedure and contine the process based on the user selection. The real problem is how to assign javascript confirm return value to the private variable declared inside Button_Click event. Please any one help me. --- Posted using Wimdows.net NntpNews Component - Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and...
9
4926
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
3
4602
by: None | last post by:
I have a small JavaScript event handler that runs when a Button is clicked. This function is called before the postback. I would like to prevent the execution of the postback in that function under a certain condition. Possible?
5
1134
by: phil | last post by:
Hi, Is this a javascript or asp.net problem? When the button is clicked, the server event in the code-behind must be executed if the user clicked on "OK" of the Confirm and not executed if clicked on "Cancel". I tried two ways: the first here below works perfect but the second way ALWAYS executes the server event!! Can anybody explain me why? Thanks
4
10026
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit" and a "delete" node. I have the functionality of the edit and delete working fine, my issue is now however that I cannot seem to find a way to add an "onclick" event that fires a confirm box. I've tried this method.. treenode.Text = "<a...
6
2532
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you get response from a Confirm() popup window to uncheck all server-side checkboxes placed in a panle of a web user control? I am using ASP.Net 2.0, Thanks. Need info...
5
13056
by: robert | last post by:
I have a dropdownlist with the autopostback set to true. I want the user to be confirm whether they do indeed want to change the value, which on post back fires a server side event (selectedindexchanged). I have tried adding an onchange attribute "return confirm('sure u wanna change this?';") but it will not postback regardless of the confirm result and the value in the list does not revert back if cancel selected. Is there a solution?
7
5212
by: shil | last post by:
Hi all, Can any one direct me in how to use javascript confirm() function when a condition is met from codebehind. I don't want to attach this to a button. When I submit the page, I want to check some business rules, and based on the response from the database, if the response is Yes, I need to display a confirmation alert to user. When the user clicks ok, then I should take an action, if not, exit out of the subroutine. Below is the...
2
2923
by: shil | last post by:
Hi all, I am using javascript confirm() function to get user's confirmation from codebehind after a condition is met. I don't want to attach the function to the button on page load. When I submit the page, I want to check some business rules, and based on the response from the database, if the response is Yes, I need to display a confirmation alert to user. When the user clicks ok, then I should take an action, if not, exit out of the...
0
9595
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
10352
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...
0
10097
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
9175
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...
0
6867
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
5535
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...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
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.