OnCommand Problem with Linkbutton as a TemplateItem

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

  1. 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
    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)
    }
    }
    , Nov 14, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vik

    OnCommand in run time

    Vik, Jul 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    415
  2. Vik

    Setting OnCommand in run time

    Vik, Jul 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    360
  3. Sheryl Landon
    Replies:
    1
    Views:
    3,573
    Ken Cox [Microsoft MVP]
    Apr 6, 2005
  4. =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=

    Using GetPostBackClientHyperlink to raise LinkButton's OnCommand e

    =?Utf-8?B?TWFyYyBXb29sZnNvbg==?=, Nov 14, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    1,140
    Marc Woolfson
    Nov 19, 2007
  5. Ross Culver

    Object Reference Not Set / GridView TemplateItem

    Ross Culver, May 9, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    728
    Ross Culver
    May 9, 2007
Loading...

Share This Page