c# - 中继器的项目命令事件未在链接按钮单击时触发

标签 c# asp.net

我的中继器的 OnItemCommand 事件有问题。
当我单击链接按钮时,它不会触发。
我是否缺少任何环境变量

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
protected void deleteResearcher(object sender, RepeaterCommandEventArgs e)
{
    string a;
    lblError.Text = e.CommandArgument.ToString();
    lblError.Visible = true;
}

最佳答案

确保不要在每次回发时重新绑定(bind)转发器。

If (Page.IsPostBack)
    return;

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

希望有帮助。

关于c# - 中继器的项目命令事件未在链接按钮单击时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9167535/

相关文章:

c# - 如何将 ValueTuple 命名功能与匿名方法一起使用?

c# - UnitOfWork 与数据库连接

具有 3 个可能返回值的 C# 合并运算符?

asp.net - 我如何决定在viewstate中存储什么?

asp.net - 错误 : EntitySet 'Building' that was specified in page markup does not exist on the Container

c# - 如果 SelectionChanged 事件触发得太快,WPF Treeview 会溢出吗?

c# - 如何使用 zlib.NET 扩充文件?

c# - 在 Silverlight 中添加 UIElementCollection DependencyProperty

asp.net - OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用。在数据对象支持(721,6)

c# - 图表控件中的多个图表系列