OnCommand Problem with Linkbutton as a TemplateItem

Discussion in 'ASP .Net' started by JSanford9482, Nov 14, 2006.

  1. JSanford9482

    JSanford9482 Guest

    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

    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">
    <asp:LinkButton ID="messageSubject" OnCommand="messageActions"
    CommandName="view" CommandArgument='<%#
    DataBinder.Eval(Container.DataItem,"Id") %>' Runat="server"><%#

    protected void messageActions(Object sender, CommandEventArgs e)
    string command = e.CommandName;
    switch (command)
    (do something)
    JSanford9482, Nov 14, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.