Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeater's Item command event is not firing on linkbutton click

Tags:

c#

asp.net

I am having problem with my repeater's OnItemCommand event. When I click the Link Button, its not firing. Am I missing any environment variable

ASPX code

<table>
    <!-- repResearchers begin, 0=display name, 1=url -->
    <asp:Repeater ID="repExtResearchers" Runat="server" OnItemCommand="deleteResearcher">
        <ItemTemplate>
            <tr>
                <td>
                    <a href="<%# ((System.String[])Container.DataItem)[1] %>">
                    <%# ((System.String[])Container.DataItem)[0] %></a>
                </td>
                <td>
                    <asp:LinkButton ID="lbDelete" runat="server" CommandName="del" 
                    CommandArgument = "<%# ((System.String[])Container.DataItem)[1]%>"
                    OnClientClick="if (!confirm('Are you sure do you want to delelte it?')) return false;">Delete</asp:LinkButton>
                </td>
            </tr>
        </ItemTemplate>
    </asp:Repeater>
</table>

CS

protected void deleteResearcher(object sender, RepeaterCommandEventArgs e)
{
    string a;
    lblError.Text = e.CommandArgument.ToString();
    lblError.Visible = true;
}
like image 676
Bhrugesh Patel Avatar asked Feb 06 '12 21:02

Bhrugesh Patel


2 Answers

Make sure you dont rebind the repeater at every postback.

If (Page.IsPostBack)
    return;

repExtResearchers.DataSource = ...
repExtResearchers.DataBind();

Hope that helps.

like image 158
Sebastian Siek Avatar answered Oct 05 '22 07:10

Sebastian Siek


I'm sure - as this is an EXTREMELY old question - that this has been answered already, but for people who may be running into what I was running into...

If you're using any of the Ajax Controls, they all require a validation group. I had a really long page that I was trying to shorten by doing this, so I wasn't noticing that the ajax controls from the Ajax Control Toolkit were throwing errors and not validating. I set the LinkButton's validation group to something that was nowhere anywhere and it started firing.

Hopefully, that helps someone out.

like image 32
Laki Politis Avatar answered Oct 05 '22 07:10

Laki Politis