i have a datalist control in my asp.net application. I would like to put the delete button inside the edititemtemplate and then add somejavascript to confirm the deletion before deleting the record.
currently the delete button is in the itemtemplate and the code works fine. the delete button also works within the edititemtemplate
the problem i have is in trying to reference the delete button once it is in the edititemtemplate. all my attempts so far have resulted in a "Object reference not set to an instance of an object.â error.
is there anyway to reference an object such as a button inside an
edititemtemplate of an asp.net control.
the code i have written which makes the 'confirm delete'
work within the itemtemplate looks like this.
(
vb.net)
sub confirm_delete (obj as object, e as datalistitemeventargs)
' edit button crashes without this if clause
If e.Item.ItemType <> ListItemType.edititem
dim deletebutton as button
deletebutton = e.item.findcontrol("btndelete")
deleteButton.Attributes("onclick") = "javascript
:return " & _
"confirm('Delete')"
end if
end sub
<asp datalist onitemdatabound = "confirm_delete" ...... />
<itemtemplate>
... all the databound stuff
<asp:Button Text="Delete" CommandName = "delete" runat =server ID = "btndelete" />
</itemtemplate>