469,889 Members | 1,258 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

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 2054
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by D. Shane Fowlkes | last post: by
12 posts views Thread by Daniel Klein | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.