处理来自中继器内 AJAX 评级控件的回发
我有一个 Repeater 控件,里面有一个 Rating 控件(来自最新的 AJAX 控件工具包):
<asp:Repeater ID="repStudents" runat="server" onitemcommand="repStudents_ItemCommand">
<ItemTemplate>
<%# Eval("FirstName") %>
<asp:Rating ID="warnings" runat="server" Direction="NotSet" MaxRating="3" StarCssClass="star" EmptyStarCssClass="em" FilledStarCssClass="gr" WaitingStarCssClass="gr" AutoPostBack="True" CommandArgument='<%# Eval("Id") %>' CommandName="warn"></asp:Rating>
<br />
</ItemTemplate>
</asp:Repeater>
在后面的代码中,我有:
protected void repStudents_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
//Custom log function
Log.Append(e.CommandName + " " + e.CommandArgument);
}
所有渲染都很好。但是,当我单击评级时,页面会发回,但不会触发 repStudents_ItemCommand
。我该如何解决这个问题?
请注意,如果我将一个按钮放在同一个中继器中,则当我单击该按钮时,repStudents_ItemCommand
会正确触发。
I have a Repeater control with a Rating control (from the latest AJAX Control Toolkit) inside:
<asp:Repeater ID="repStudents" runat="server" onitemcommand="repStudents_ItemCommand">
<ItemTemplate>
<%# Eval("FirstName") %>
<asp:Rating ID="warnings" runat="server" Direction="NotSet" MaxRating="3" StarCssClass="star" EmptyStarCssClass="em" FilledStarCssClass="gr" WaitingStarCssClass="gr" AutoPostBack="True" CommandArgument='<%# Eval("Id") %>' CommandName="warn"></asp:Rating>
<br />
</ItemTemplate>
</asp:Repeater>
In the code behind, I have:
protected void repStudents_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
//Custom log function
Log.Append(e.CommandName + " " + e.CommandArgument);
}
All renders fine. However, when I click on a rating the page posts back but repStudents_ItemCommand
is not fired. How can I fix this?
Note that if I put a Button in the same Repeater, repStudents_ItemCommand
fires correctly when I click the button.
Rating 控件不支持 CommandName/CommandArgument 属性。但您可以按如下方式扩展它:
然后用新控件替换旧控件:
The Rating control does not support CommandName/CommandArgument properties. But you can extend it as follows:
Then replace the old control with new one: