472,353 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgItem.ItemCreated

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

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

objDeleteButton.CssClass = "inputbutton"

objDeleteButton.Attributes.Add("onClick", "confirmDeleteItem();")

End If

End Sub

' client side code in javascript

function confirmDeleteItem()

{

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 2143
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" <elliotmrodriguezatnospamhotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.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_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgItem.ItemCreated
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

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

objDeleteButton.CssClass = "inputbutton"

objDeleteButton.Attributes.Add("onClick", "confirmDeleteItem();")

End If

End Sub

' client side code in javascript

function confirmDeleteItem()

{

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" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:uV**************@tk2msftngp13.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" <elliotmrodriguezatnospamhotmail.com> wrote in message news:%2****************@TK2MSFTNGP09.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_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles

dgItem.ItemCreated

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

Dim objDeleteButton As Button = CType(e.Item.Cells(1).Controls(0), Button)
objDeleteButton.CssClass = "inputbutton"

objDeleteButton.Attributes.Add("onClick", "confirmDeleteItem();")

End If

End Sub

' client side code in javascript

function confirmDeleteItem()

{

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**************@TK2MSFTNGP10.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" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:uV**************@tk2msftngp13.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" <elliotmrodriguezatnospamhotmail.com> wrote in

message
news:%2****************@TK2MSFTNGP09.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_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles

dgItem.ItemCreated

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

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

Button)
objDeleteButton.CssClass = "inputbutton"

objDeleteButton.Attributes.Add("onClick", "confirmDeleteItem();")

End If

End Sub

' client side code in javascript

function confirmDeleteItem()

{

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" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:Ow**************@TK2MSFTNGP12.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**************@TK2MSFTNGP10.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" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:uV**************@tk2msftngp13.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" <elliotmrodriguezatnospamhotmail.com> wrote in

message
news:%2****************@TK2MSFTNGP09.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_ItemCreated(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgItem.ItemCreated
>
> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
> ListItemType.AlternatingItem Then
>
> Dim objDeleteButton As Button = CType(e.Item.Cells(1).Controls(0),

Button)
>
> objDeleteButton.CssClass = "inputbutton"
>
> objDeleteButton.Attributes.Add("onClick", "confirmDeleteItem();")
>
> End If
>
> End Sub
>
>
>
> ' client side code in javascript
>
> function confirmDeleteItem()
>
> {
>
> 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
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...
2
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...
7
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...
4
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...
2
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...
9
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
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...
12
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.