I have a ListView
that has Update and Cancel buttons. Both of these buttons have a CommandName
of Cancel, so they fire the same ListView
event handler (ListView_ItemCanceling).
Inside this event handle I execute my stored procedures. The issue I am having is since both buttons fire the same event handler they both update. Even if there are no changes being made.
I would like to try to determine the button that has fired the event at the start of the event handler (possibly using sender?), but I cannot figure out how to do this.
This is what I was currently trying to do in the ListView_ItemCancelling
event handler:
Button newButton = (Button)sender;
if(newButton.Text == "Cancel")
{
Console.Write("this worked");
}
When I execute this code I get an error message telling me that I cannot convert the sender object from ListView
object to a Button
object.
Any help will be greatly appreciated!