OnCommand Problem with Linkbutton as a TemplateItem

J

JSanford9482

Hi All,

I have a Repeater that contains a LinkButton as one of the items in the
ItemTemplate. I have the OnCommand (method is called "messageActions")
and CommandName ("view") properties set, as well as a CommandArgument
for the LinkButton to fire off when clicked. For some reason, when I
try to set the CommandEventHandler for the LinkButton:

this.messageSubject.Command += new CommandEventHandler(messageActions);


I get an object reference runtime error. I have the LinkButton
delcared.

Can someone give me an example on the correct way to set this up so my
method will fire? My code snippet is below. Thanks so much in advance!

<asp:Repeater ID="messageRepeater" Runat="server">
<ItemTemplate>
<asp:LinkButton ID="messageSubject" OnCommand="messageActions"
CommandName="view" CommandArgument='<%#
DataBinder.Eval(Container.DataItem,"Id") %>' Runat="server"><%#
DataBinder.Eval(Container.DataItem,"MessageSubject")
%></asp:LinkButton>
</ItemTemplate>

protected void messageActions(Object sender, CommandEventArgs e)
{
string command = e.CommandName;
switch (command)
{
(do something)
}
}
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top