DataList.DeleteCommand event is not getting fired

N

Nathan Sokalski

I have a DataList that has an Button as one of the controls in it's
ItemTemplate. The Button has a CommandName="delete" attribute, but when I
click it the DeleteCommand event doesn't even get fired. I have checked
everything I could think of, but everything looks correct to me. Here is the
relevant code from the *.aspx file and the *.aspx.vb files (if I missed
something that is relevant, let me know):


ASPX File:

<asp:datalist id="datImages" runat="server" EnableViewState="False"
CellPadding="0" CellSpacing="5" RepeatColumns="3"
RepeatDirection="Horizontal" DataKeyField="contentid">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom"></ItemStyle>
<ItemTemplate>
<uc1:captionimage id="CapImg" runat="server" EnableViewState="False"
photo='<%#
DataBinder.Eval(Container,"DataItem.content","newsinfo/{0}").Trim() %>'
caption='<%# DataBinder.Eval(Container, "DataItem.textcaption").Trim()
%>'></uc1:captionimage><BR><BR>
<asp:Button id="btnDeleteImg" runat="server" CausesValidation="False"
Font-Bold="True" EnableViewState="False" Text="Delete"
CommandName="delete"></asp:Button>
</ItemTemplate>
</asp:datalist>



ASPX.VB File:

Private Sub datImages_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs) Handles
datImages.DeleteCommand
Dim cmdDelete As New OleDbCommand("DELETE FROM newsinfo WHERE contentid=" &
CInt(datLinksFiles.DataKeys(e.Item.ItemIndex)), New
OleDbConnection(Global.connectionstring))

cmdDelete.Connection.Open()
cmdDelete.ExecuteNonQuery()
cmdDelete.Connection.Close()
If System.IO.File.Exists(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content")))) Then
System.IO.File.Delete(Server.MapPath("newsinfo/" &
CStr(CType(e.Item.DataItem, DataRowView).Row("content"))))
Me.RefreshResults()
End Sub


Does anybody have any idea what could be causing the datImages.DeleteCommand
event not to be raised? Thank you.
 
G

Guest

it seems you havent bind DataList Ondelete Command ... OnDeleteCommand =
"datImages_DeleteCommand" in data list properties in html
 
N

Nathan Sokalski

That is not how event bubbling is done. I have several other applications
that I use the DeleteCommand event in, and I don't need to do any manual
binding in those, I even have another DataList on this same page, and that
one works. The connection between the event and the event handler is done
using the "Handles" clause in VB.NET, which I have if you look at the code I
included in my original posting. Any other suggestions?
 
G

Guest

Does your another datalist has itemtemplate and button in item template????
Have you tried my solution??? There is no harm in writing one line in html i
think .... I have checked on my side and its work when ondeletecommand is
specified otherwise not. And you said about event bubbling ... Before event
bubbling postback javascript is generated which calls particular event
handler :) if you dont tell to your datalist who is handling delete command
what will be written in generated postback javascript?????
 
N

Nathan Sokalski

My other DataList has a Button in the ItemTemplate, they are almost the same
except for the data that they are binded to. But because you are not
supposed to need to add the code you mentioned, it means that something
somewhere got accidentally changed, and I want to know what & where that is
(if I always ignore stuff and do it the way it was not intended to be done,
what will happen when MS decides to make changes? How inefficient and sloppy
will my code be eventually? I think that when something doesn't work as
expected, I need to learn why so I can use it in the future in other
scenarios).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top