简体   繁体   English

在链接按钮单击时,不会触发Repeater的Item命令事件

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

I am having problem with my repeater's OnItemCommand event. 我的转发器的OnItemCommand事件有问题。 When I click the Link Button, its not firing. 当我单击链接按钮时,它不会触发。 Am I missing any environment variable 我错过了任何环境变量

ASPX code ASPX代码

<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 CS

protected void deleteResearcher(object sender, RepeaterCommandEventArgs e)
{
    string a;
    lblError.Text = e.CommandArgument.ToString();
    lblError.Visible = true;
}

Make sure you dont rebind the repeater at every postback. 确保你不要在每次回发时重新绑定转发器。

If (Page.IsPostBack)
    return;

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

Hope that helps. 希望有所帮助。

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. 如果您使用任何Ajax控件,则它们都需要验证组。 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. 我有一个很长的页面,我试图通过这样做缩短,所以我没有注意到Ajax Control Toolkit的ajax控件抛出错误而没有验证。 I set the LinkButton's validation group to something that was nowhere anywhere and it started firing. 我将LinkBut​​ton的验证组设置为无处可寻的东西,并开始触发。

Hopefully, that helps someone out. 希望,这可以帮助某人。

I had this issue using OnCommand in a LinkButton and I had an empty href="" . 我在LinkButton使用OnCommand遇到了这个问题,我有一个空的href="" When I removed the extra attribute, it posted back. 当我删除额外属性时,它会回发。

It won't fix your ptoblem but change 它不会修复你的问题而是改变

OnClientClick="if (!confirm('Are you sure do you want to delelte it?')) return false;"

to

OnClientClick="return confirm('Are you sure do you want to delelte it?')"

Your code is using a double negative to confirm a positive. 您的代码使用双重否定来确认肯定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM