M
mikelor
Hi,
I have a repeater control with more than one LinkButton. I know I can
use the ItemCommand event handler for the repeater control to catch the
LinkButton Command events as long as I give each LinkButton a unique
command name I can do something like this
private void MyRepeater_ItemCommand( Object o, RepeaterEventArgs e )
{
switch( e.CommandName )
{
case "Edit":
DoEdit();
case "Delete"
DoDelete();
}
}
However what I would like to do is have a event handler for each
LinkButton Command Event
private void EditLinkButton_Command( Object o, CommandEventArgs e )
{
DoEdit();
}
private void DeleteLinkButton_Command( Object o, CommandEventArgs e )
{
DoDelete();
}
The second way seems a bit cleaner to me. However when I try and add
the event handler I get a null reference exception on the
editLinkButton object
this.editLinkButton.Command += new CommandEventHandler(
this.EditLinkButton_Command )
Even though I have
<asp:LinkButton id="editLinkButton" ...>Edit</asp> in my repeater and
have delclared
protected LinkButton editLinkButton;
in my codebehind.
Like I said, I can get it to work using the ItemCommand event handler,
but it seems a bit messy to me to use the switch case to determin the
object sending the event. However all code that I've searched for seems
to do it this way..
Any other ideas?
-=mike
I have a repeater control with more than one LinkButton. I know I can
use the ItemCommand event handler for the repeater control to catch the
LinkButton Command events as long as I give each LinkButton a unique
command name I can do something like this
private void MyRepeater_ItemCommand( Object o, RepeaterEventArgs e )
{
switch( e.CommandName )
{
case "Edit":
DoEdit();
case "Delete"
DoDelete();
}
}
However what I would like to do is have a event handler for each
LinkButton Command Event
private void EditLinkButton_Command( Object o, CommandEventArgs e )
{
DoEdit();
}
private void DeleteLinkButton_Command( Object o, CommandEventArgs e )
{
DoDelete();
}
The second way seems a bit cleaner to me. However when I try and add
the event handler I get a null reference exception on the
editLinkButton object
this.editLinkButton.Command += new CommandEventHandler(
this.EditLinkButton_Command )
Even though I have
<asp:LinkButton id="editLinkButton" ...>Edit</asp> in my repeater and
have delclared
protected LinkButton editLinkButton;
in my codebehind.
Like I said, I can get it to work using the ItemCommand event handler,
but it seems a bit messy to me to use the switch case to determin the
object sending the event. However all code that I've searched for seems
to do it this way..
Any other ideas?
-=mike