473,465 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Delete Confirmation

I want to add a confirmation dialog box before I delete
the records in my form.

I have a piece of javascript code in html that checks for
confirmation. But the main issue lies in calling this
javascript function on pagebehind.

function confirm_delete()
{
if (confirm("Are you sure you want
to delete this item?")==true)
return true;
else
return false;
}

I use btndelete.attributes.add("onclick", "return
confirm_delete();") in the page load event which also
works fine.

But this event fires each time I click the button,
irrespective of whether there are records or not. And I do
not want this to happen. I want this confirmation to pop
up only when the form contains the records.

I also tried putting in an if condition around it like:

if txtID.text<>""
btndelete.attributes.add("onclick", "return confirm_delete
();")
End if

But this works fine only for the first time. Sometimes it
would'nt work also.

Please help.

Nov 17 '05 #1
6 1654

"Dotnet Guy" <an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
I want to add a confirmation dialog box before I delete
the records in my form.

I have a piece of javascript code in html that checks for
confirmation. But the main issue lies in calling this
javascript function on pagebehind.

function confirm_delete()
{
if (confirm("Are you sure you want
to delete this item?")==true)
return true;
else
return false;
}


This is a bit lengthy, you can shorten it to:

function confirm_delete()
{
return confirm("Are you sure you want to delete this item?");
}
Hans Kesting
Nov 17 '05 #2
Thats ok. But that does'nt solve my problem. Is there
anyway to fix my problem?

Thanks.
-----Original Message-----

"Dotnet Guy" <an*******@discussions.microsoft.com> wrote in messagenews:0a****************************@phx.gbl...

This is a bit lengthy, you can shorten it to:

function confirm_delete()
{
return confirm("Are you sure you want to delete this item?"); }
Hans Kesting
.

Nov 17 '05 #3
Hi Dotnet Guy,



First please change your name that it reflects your real name unless your parents really named you Dotnet Guy in which case I'm sorry ;-) People would like to know with whom they are talking.



Regarding your question try the following:



aspx

<!-- put this piece code in the aspx part of your page -->

<form id="Form1" method="post" runat="server">

<input type="button" value="Delete Item" onserverclick=" btnDeleteItem" onclick="if(!confirm(' Are you sure you want to delete this item?')){return false;}"

runat="server" ID="btnDeleteItem" NAME=" btnDeleteItem ">

</form>



vb

' and add this piece of Code to your code behind page

Public Sub btnDeleteItem(ByVal sender As System.Object, ByVal e As System.EventArgs)

' here is your code doing what ever is needed to delete the item

End Sub



I hope this solves your problem.

Best regards
Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.



"Dotnet guy" <sk*****@comsult.com> schrieb im Newsbeitrag news:06****************************@phx.gbl...
Thats ok. But that does'nt solve my problem. Is there
anyway to fix my problem?

Thanks.


-----Original Message-----

"Dotnet Guy" <an*******@discussions.microsoft.com> wrote

in message
news:0a****************************@phx.gbl...

This is a bit lengthy, you can shorten it to:

function confirm_delete()
{
return confirm("Are you sure you want to delete this

item?");
}
Hans Kesting
.

Nov 17 '05 #4
Hi Dotnet Guy,



First please change your name that it reflects your real name unless your parents really named you Dotnet Guy in which case I'm sorry ;-) People would like to know with whom they are talking.



Regarding your question try the following:



aspx

<!-- put this piece code in the aspx part of your page -->

<form id="Form1" method="post" runat="server">

<input type="button" value="Delete Item" onserverclick=" btnDeleteItem" onclick="if(!confirm(' Are you sure you want to delete this item?')){return false;}"

runat="server" ID="btnDeleteItem" NAME=" btnDeleteItem ">

</form>



vb

' and add this piece of Code to your code behind page

Public Sub btnDeleteItem(ByVal sender As System.Object, ByVal e As System.EventArgs)

' here is your code doing what ever is needed to delete the item

End Sub



I hope this solves your problem.

Best regards
Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.



"Dotnet guy" <sk*****@comsult.com> schrieb im Newsbeitrag news:06****************************@phx.gbl...
Thats ok. But that does'nt solve my problem. Is there
anyway to fix my problem?

Thanks.


-----Original Message-----

"Dotnet Guy" <an*******@discussions.microsoft.com> wrote

in message
news:0a****************************@phx.gbl...

This is a bit lengthy, you can shorten it to:

function confirm_delete()
{
return confirm("Are you sure you want to delete this

item?");
}
Hans Kesting
.

Nov 17 '05 #5
I don't know if this is the solution that you are after, but in the
Load event of your page why don't you check to see if any records
exist. If no records exist, why don't you disable your delete button
so it can't be clicked. This should prevent the event from firing as
the button cannot be clicked.

HTH
Dwayne
Nov 17 '05 #6
I don't know if this is the solution that you are after, but in the
Load event of your page why don't you check to see if any records
exist. If no records exist, why don't you disable your delete button
so it can't be clicked. This should prevent the event from firing as
the button cannot be clicked.

HTH
Dwayne
Nov 17 '05 #7

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

Similar topics

2
by: Les Juby | last post by:
I've used a simple javascript for some time (no entries required up in the <head> tag) that asks for a confirmation before deleting. ie. <a href="/delete.asp?which=345 %>"...
4
by: Stephen | last post by:
Hello People, Using MS Access 2003 VBA I get the error 3020 Update or CancelUpdate without AddNew or Edit when I run through the following code. Can anyone help suggest anything to try? Thanks....
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
4
by: DrData | last post by:
I'm working on an ASP.Net application written in C#. On one page, there are several datagrid controls used to display, edit and delete detail records relating to the master record also displayed on...
0
by: Elton W | last post by:
Hi Peter, You use DeleteButton.Attributes.Add("onclick", "return confirm ('Are you sure you want to delete?');"); in datagrid_ItemDataBound event to add confirmation for delete button.
0
by: Suzanne | last post by:
I'd like to know how can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key? I have found this code on...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
0
by: johnmott | last post by:
Hi all, One of the limitations of the GridView control is that the built-in delete processing doesn't prompt for confirmation -- something thats very important for a user interface. True, you...
0
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.