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.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:%23xSgcJ$wDHA.2092@.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.
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:uV5h$Y$wDHA.3220@.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:%23xSgcJ$wDHA.2092@.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.
Aha - that's a special case I hadn't considered.
Try this article:
http://authors.aspalliance.com/aldo...xamples/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:ucDxzLAxDHA.2460@.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:uV5h$Y$wDHA.3220@.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:%23xSgcJ$wDHA.2092@.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.
> >
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:OwfPeBBxDHA.1196@.TK2MSFTNGP12.phx.gbl...
> Aha - that's a special case I hadn't considered.
> Try this article:
> http://authors.aspalliance.com/aldo...xamples/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:ucDxzLAxDHA.2460@.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:uV5h$Y$wDHA.3220@.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:%23xSgcJ$wDHA.2092@.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.
> > > > > >