Link buttons don't fire ItemCommand in repeater control, is this a bug?

Discussion in 'ASP .Net' started by Stan, Dec 2, 2003.

  1. Stan

    Stan Guest

    I cannot make the link buttons fire ItemCommand from
    repeater control.

    Here is the code:

    <asp:repeater id=rptLetters runat="server">
    <itemtemplate>
    <asp:linkbutton id="lnkLetter"
    runat="server" commandname="Filter"
    CommandArgument='<%#
    DataBinder.Eval(Container, "DataItem.Letter")%>'>
    <%# DataBinder.Eval
    (Container, "DataItem.Letter")%>
    </asp:linkbutton>
    </itemtemplate>
    </asp:repeater>

    In code-behind I've got:

    this.rptLetters.ItemCommand += new
    System.Web.UI.WebControls.RepeaterCommandEventHandler
    (this.OnLetterClicked);

    and

    protected void OnLetterClicked(object source,
    System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    {
    if (e.CommandName == "Filter")
    {
    letterFilter = (string)
    e.CommandArgument;
    PopulateGrid();
    }
    }

    and it is does not fire the click event!


    However, if I replace link button with regular buttons

    <asp:repeater id=rptLetters runat="server">
    <itemtemplate>
    <asp:button id="lnkLetter" runat="server"
    commandname="Filter"
    CommandArgument='<%#
    DataBinder.Eval(Container, "DataItem.Letter")%>'
    Text='<%# DataBinder.Eval
    (Container, "DataItem.Letter")%>' />
    </itemtemplate>
    </asp:repeater>

    exactly the the same code works fine.

    I am using 1.0.3705 framework.

    Is this a bug?

    Thanks,

    -Stan
     
    Stan, Dec 2, 2003
    #1
    1. Advertising

  2. Hi Stan,

    Based on my research and experience, the following information is useful to
    you. Please refer to it carefully.

    DataList.ItemCommand Event
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemwebuiwebcontrolsdatalistclassitemcommandtopic.asp
    "...
    The ItemCommand event is raised when any button is clicked in the DataList
    control and is commonly used when you have a button control with a custom
    CommandName value.
    ...
    The following example demonstrates how to specify and code a handler for
    the ItemCommand event to select an item from the DataList control.
    ...
    <ItemTemplate>

    <asp:LinkButton id="SelectButton"
    Text="Select"
    CommandName="Select"
    runat="server"/>

    Item <%# DataBinder.Eval(Container.DataItem, "Item") %>

    </ItemTemplate>
    ..."

    If I have misunderstood your concern, please feel free to let me know.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    Get Secure! ┬ĘC www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jacob Yang [MSFT], Dec 3, 2003
    #2
    1. Advertising

  3. Since this is in a data repeater the code fires the ItemCommand for the data
    repeater instead of the LinkButton. This sounds strange but really works
    out becuase sometime you can get away without sending any parameters, if the
    data you need is in on DataRepeater Item.

    To see if this is happening create an event handler for the Repeater control
    and put a Messagebox.Show as the only line of code. The everytime you click
    the link the message should popup. You can even sent a breakpoint on the
    MessageBox.Show and view what data you can access from the datarepeater
    using the e.Item object. I have used this numerous times, but the first
    time it was very frustrating learning how to extract data from the
    datarepeater. Feel free to send me any more questions you might have.

    S. Shawn Mehaffie





    "Stan" <> wrote in message
    news:b43901c3b8f1$c6300210$...
    > I cannot make the link buttons fire ItemCommand from
    > repeater control.
    >
    > Here is the code:
    >
    > <asp:repeater id=rptLetters runat="server">
    > <itemtemplate>
    > <asp:linkbutton id="lnkLetter"
    > runat="server" commandname="Filter"
    > CommandArgument='<%#
    > DataBinder.Eval(Container, "DataItem.Letter")%>'>
    > <%# DataBinder.Eval
    > (Container, "DataItem.Letter")%>
    > </asp:linkbutton>
    > </itemtemplate>
    > </asp:repeater>
    >
    > In code-behind I've got:
    >
    > this.rptLetters.ItemCommand += new
    > System.Web.UI.WebControls.RepeaterCommandEventHandler
    > (this.OnLetterClicked);
    >
    > and
    >
    > protected void OnLetterClicked(object source,
    > System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    > {
    > if (e.CommandName == "Filter")
    > {
    > letterFilter = (string)
    > e.CommandArgument;
    > PopulateGrid();
    > }
    > }
    >
    > and it is does not fire the click event!
    >
    >
    > However, if I replace link button with regular buttons
    >
    > <asp:repeater id=rptLetters runat="server">
    > <itemtemplate>
    > <asp:button id="lnkLetter" runat="server"
    > commandname="Filter"
    > CommandArgument='<%#
    > DataBinder.Eval(Container, "DataItem.Letter")%>'
    > Text='<%# DataBinder.Eval
    > (Container, "DataItem.Letter")%>' />
    > </itemtemplate>
    > </asp:repeater>
    >
    > exactly the the same code works fine.
    >
    > I am using 1.0.3705 framework.
    >
    > Is this a bug?
    >
    > Thanks,
    >
    > -Stan
    >
     
    Shawn Mehaffie, Jan 22, 2004
    #3
    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. Nick Gilbert
    Replies:
    2
    Views:
    907
    Jeffrey Tan[MSFT]
    Dec 15, 2003
  2. Jeremy
    Replies:
    0
    Views:
    402
    Jeremy
    Jul 2, 2004
  3. Nick Gilbert
    Replies:
    4
    Views:
    268
    Jeffrey Tan[MSFT]
    Dec 16, 2003
  4. Mark Sisson

    What doesn't an ItemTemplate child control fire an ItemCommand??

    Mark Sisson, Dec 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    192
    Mark Sisson
    Dec 17, 2003
  5. Krushna

    Repeater ItemCommand does not fire the first time

    Krushna, Jul 29, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    189
    Krushna
    Jul 29, 2005
Loading...

Share This Page