[英]Repeater's Item command event is not firing on linkbutton click
我的转发器的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;
}
确保你不要在每次回发时重新绑定转发器。
If (Page.IsPostBack)
return;
repExtResearchers.DataSource = ...
repExtResearchers.DataBind();
希望有所帮助。
我敢肯定 - 因为这是一个非常古老的问题 - 这已经得到了回答,但对于那些可能遇到我遇到的问题的人来说......
如果您使用任何Ajax控件,则它们都需要验证组。 我有一个很长的页面,我试图通过这样做缩短,所以我没有注意到Ajax Control Toolkit的ajax控件抛出错误而没有验证。 我将LinkButton的验证组设置为无处可寻的东西,并开始触发。
希望,这可以帮助某人。
我在LinkButton
使用OnCommand
遇到了这个问题,我有一个空的href=""
。 当我删除额外属性时,它会回发。
它不会修复你的问题而是改变
OnClientClick="if (!confirm('Are you sure do you want to delelte it?')) return false;"
至
OnClientClick="return confirm('Are you sure do you want to delelte it?')"
您的代码使用双重否定来确认肯定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.