473,544 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

suppressing Submit command with a Delete button

I have a Delete button in my datagrid. I'm attempting to add some code
confirming whether the user wishes to really delete the item or not.

The confirm pops up, but I cannot suppress the submission when selecting
Cancel.

Heres what I have so far:

' adding the javascript call to the button:
Private Sub dgItem_ItemCrea ted(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles dgItem.ItemCrea ted

If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItemType.Al ternatingItem Then

Dim objDeleteButton As Button = CType(e.Item.Ce lls(1).Controls (0), Button)

objDeleteButton .CssClass = "inputbutto n"

objDeleteButton .Attributes.Add ("onClick", "confirmDeleteI tem();")

End If

End Sub

' client side code in javascript

function confirmDeleteIt em()

{

if (confirm("Are you sure you wish to delete this item?"))

{

return true;

}

else

{

return false;

}

}

any help is appreciated. thank you.
Nov 18 '05 #1
4 2247
Sounds like you have validation controls on there, which causes the runtime
to emit yet another onClick handler which submits the form. Try using an
<input type="button"> instead of an <asp:button> control, and if you need
validation just script in the validation call (and, as always, make sure you
explicitly validate on the server, as client side validation is easy to
foil).

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Elliot M. Rodriguez" <elliotmrodrigu ezatnospamhotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a Delete button in my datagrid. I'm attempting to add some code
confirming whether the user wishes to really delete the item or not.

The confirm pops up, but I cannot suppress the submission when selecting
Cancel.

Heres what I have so far:

' adding the javascript call to the button:
Private Sub dgItem_ItemCrea ted(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles dgItem.ItemCrea ted
If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItemType.Al ternatingItem Then

Dim objDeleteButton As Button = CType(e.Item.Ce lls(1).Controls (0), Button)

objDeleteButton .CssClass = "inputbutto n"

objDeleteButton .Attributes.Add ("onClick", "confirmDeleteI tem();")

End If

End Sub

' client side code in javascript

function confirmDeleteIt em()

{

if (confirm("Are you sure you wish to delete this item?"))

{

return true;

}

else

{

return false;

}

}

any help is appreciated. thank you.

Nov 18 '05 #2
Chris:

Thanks for the reply. I am struggling with this.

If I take your approach it seems I dont have the ability to wire it to the
DeleteCommand event. This means I have to access the DataKey for the row
through the client, which I dont want to do. I could be wrong on this
though.

All I really want to do is have a DeleteCommand button that performs a
delete with a confirmation prior to deletion. My code does not have any
other validators on the page. There is another button on the page, but
performs a completely unrelated task.
"Chris Jackson" <chrisjATmvpsDO TorgNOSPAM> wrote in message
news:uV******** ******@tk2msftn gp13.phx.gbl...
Sounds like you have validation controls on there, which causes the runtime to emit yet another onClick handler which submits the form. Try using an
<input type="button"> instead of an <asp:button> control, and if you need
validation just script in the validation call (and, as always, make sure you explicitly validate on the server, as client side validation is easy to
foil).

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Elliot M. Rodriguez" <elliotmrodrigu ezatnospamhotma il.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a Delete button in my datagrid. I'm attempting to add some code
confirming whether the user wishes to really delete the item or not.

The confirm pops up, but I cannot suppress the submission when selecting
Cancel.

Heres what I have so far:

' adding the javascript call to the button:
Private Sub dgItem_ItemCrea ted(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles

dgItem.ItemCrea ted

If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItemType.Al ternatingItem Then

Dim objDeleteButton As Button = CType(e.Item.Ce lls(1).Controls (0), Button)
objDeleteButton .CssClass = "inputbutto n"

objDeleteButton .Attributes.Add ("onClick", "confirmDeleteI tem();")

End If

End Sub

' client side code in javascript

function confirmDeleteIt em()

{

if (confirm("Are you sure you wish to delete this item?"))

{

return true;

}

else

{

return false;

}

}

any help is appreciated. thank you.


Nov 18 '05 #3
Aha - that's a special case I hadn't considered.

Try this article:

http://authors.aspalliance.com/aldot...amples/cd.aspx
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Elliot M. Rodriguez" <someemail> wrote in message
news:uc******** ******@TK2MSFTN GP10.phx.gbl...
Chris:

Thanks for the reply. I am struggling with this.

If I take your approach it seems I dont have the ability to wire it to the
DeleteCommand event. This means I have to access the DataKey for the row
through the client, which I dont want to do. I could be wrong on this
though.

All I really want to do is have a DeleteCommand button that performs a
delete with a confirmation prior to deletion. My code does not have any
other validators on the page. There is another button on the page, but
performs a completely unrelated task.
"Chris Jackson" <chrisjATmvpsDO TorgNOSPAM> wrote in message
news:uV******** ******@tk2msftn gp13.phx.gbl...
Sounds like you have validation controls on there, which causes the

runtime
to emit yet another onClick handler which submits the form. Try using an
<input type="button"> instead of an <asp:button> control, and if you need
validation just script in the validation call (and, as always, make sure

you
explicitly validate on the server, as client side validation is easy to
foil).

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Elliot M. Rodriguez" <elliotmrodrigu ezatnospamhotma il.com> wrote in

message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a Delete button in my datagrid. I'm attempting to add some code
confirming whether the user wishes to really delete the item or not.

The confirm pops up, but I cannot suppress the submission when selecting Cancel.

Heres what I have so far:

' adding the javascript call to the button:
Private Sub dgItem_ItemCrea ted(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles

dgItem.ItemCrea ted

If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItemType.Al ternatingItem Then

Dim objDeleteButton As Button = CType(e.Item.Ce lls(1).Controls (0),

Button)
objDeleteButton .CssClass = "inputbutto n"

objDeleteButton .Attributes.Add ("onClick", "confirmDeleteI tem();")

End If

End Sub

' client side code in javascript

function confirmDeleteIt em()

{

if (confirm("Are you sure you wish to delete this item?"))

{

return true;

}

else

{

return false;

}

}

any help is appreciated. thank you.



Nov 18 '05 #4
Chris:

I realized I forgot the lousy "return" keyword in Attributes.Add lol...
Thanks for the article and the help.

"Chris Jackson" <chrisjATmvpsDO TorgNOSPAM> wrote in message
news:Ow******** ******@TK2MSFTN GP12.phx.gbl...
Aha - that's a special case I hadn't considered.

Try this article:

http://authors.aspalliance.com/aldot...amples/cd.aspx
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Elliot M. Rodriguez" <someemail> wrote in message
news:uc******** ******@TK2MSFTN GP10.phx.gbl...
Chris:

Thanks for the reply. I am struggling with this.

If I take your approach it seems I dont have the ability to wire it to the
DeleteCommand event. This means I have to access the DataKey for the row
through the client, which I dont want to do. I could be wrong on this
though.

All I really want to do is have a DeleteCommand button that performs a
delete with a confirmation prior to deletion. My code does not have any
other validators on the page. There is another button on the page, but
performs a completely unrelated task.
"Chris Jackson" <chrisjATmvpsDO TorgNOSPAM> wrote in message
news:uV******** ******@tk2msftn gp13.phx.gbl...
Sounds like you have validation controls on there, which causes the

runtime
to emit yet another onClick handler which submits the form. Try using an <input type="button"> instead of an <asp:button> control, and if you need validation just script in the validation call (and, as always, make sure you
explicitly validate on the server, as client side validation is easy
to foil).

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Elliot M. Rodriguez" <elliotmrodrigu ezatnospamhotma il.com> wrote in

message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> I have a Delete button in my datagrid. I'm attempting to add some code > confirming whether the user wishes to really delete the item or not.
>
> The confirm pops up, but I cannot suppress the submission when

selecting > Cancel.
>
> Heres what I have so far:
>
> ' adding the javascript call to the button:
> Private Sub dgItem_ItemCrea ted(ByVal sender As Object, ByVal e As
> System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
dgItem.ItemCrea ted
>
> If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
> ListItemType.Al ternatingItem Then
>
> Dim objDeleteButton As Button = CType(e.Item.Ce lls(1).Controls (0),

Button)
>
> objDeleteButton .CssClass = "inputbutto n"
>
> objDeleteButton .Attributes.Add ("onClick", "confirmDeleteI tem();")
>
> End If
>
> End Sub
>
>
>
> ' client side code in javascript
>
> function confirmDeleteIt em()
>
> {
>
> if (confirm("Are you sure you wish to delete this item?"))
>
> {
>
> return true;
>
> }
>
> else
>
> {
>
> return false;
>
> }
>
> }
>
> any help is appreciated. thank you.
>
>



Nov 18 '05 #5

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

Similar topics

4
4280
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field that has been modified/clicked the form doesn't always submit. When it does work, a Stored procedure is passed form variables and updates to the db...
2
17173
by: sandyde2 | last post by:
Hi all, I get the tough problem and expect to get help.. In a html page, I dynamically created many forms which named as NO+business_id. In each form there are two submit buttons to "release_or_not". of course in the server side I validate those values as well. However, because this page is for admin to use so that I do not need to care...
7
1986
by: sindre | last post by:
Hi, Some place I use links to submit forms instead of a submit button. The way I have done this is: <a href="javascript:document.getElementById('<?php print "delete$i" ;?>').submit()>Delete?</a>. This method worked perfectly fine. But then I also wanted to add a confirm box to the user where. A confirm("do you really want to delete?")....
4
4922
by: gimme_this_gimme_that | last post by:
Hi, This is sort of a : How to build a Yes/No dialog box qquestion. Or perhaps a question about getting javascript variables from a pop-up window and processing them on a submit. This is what I'd like to have happen :
2
9269
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which reads "Invalid use of null". The remainder of the options in the Command Button Wizard are then unavailable and the button wil not work. The only...
9
5711
by: Melissa | last post by:
What is the code to delete a command button from a form? Can the code be run from the click event of the button to be deleted? Thanks! Melissa
3
2550
by: D. Shane Fowlkes | last post by:
Sorry for the length of this post. I have created a rather complex form which has a header/line item (parent and child records) structure. It's for an intranet. A screenshot can be seen here: http://www.drpt.virginia.gov/temp1.gif All the fields on this form have validation controls on them so they can not submit the form unless all...
12
6920
by: Daniel Klein | last post by:
I'm pretty new at php and web stuff so please be gentle with me. I'm trying to get a form to submit when the user presses the Enter key. I do not want to use javascript. I've googled this to death and cant find the answer (only hints), except on the 'Experts Exhange' page and you have to pay to get the answer :-( Why is this such a secret...
0
7417
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...
0
7361
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...
0
7601
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. ...
1
7365
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...
0
7701
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...
1
5289
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3404
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...
0
3402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1834
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

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.