处理来自中继器内 AJAX 评级控件的回发

发布于 12-07 16:39 字数 985 浏览 1 评论 0原文

我有一个 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

超可爱的懒熊2024-12-14 16:39:52

Rating 控件不支持 CommandName/CommandArgument 属性。但您可以按如下方式扩展它:

public class ExRating : Rating {

    [Category("Behavior")]
    public string CommandName {
        get { return (string)ViewState["CommandName"] ?? string.Empty; }
        set { ViewState["CommandName"] = value; }
    }

    [Category("Behavior")]
    public string CommandArgument {
        get { return (string)ViewState["CommandArgument"] ?? string.Empty; }
        set { ViewState["CommandArgument"] = value; }
    }

    protected override void OnChanged(RatingEventArgs e) {
        base.OnChanged(e);
        RaiseBubbleEvent(this, new CommandEventArgs(CommandName, CommandArgument));
    }

}

然后用新控件替换旧控件:

<pages>
  <tagMapping>
    <add tagType="AjaxControlToolkit.Rating, AjaxControlToolkit" mappedTagType="Sample.ExRating, Sample"/>
  </tagMapping>
</pages>

The Rating control does not support CommandName/CommandArgument properties. But you can extend it as follows:

public class ExRating : Rating {

    [Category("Behavior")]
    public string CommandName {
        get { return (string)ViewState["CommandName"] ?? string.Empty; }
        set { ViewState["CommandName"] = value; }
    }

    [Category("Behavior")]
    public string CommandArgument {
        get { return (string)ViewState["CommandArgument"] ?? string.Empty; }
        set { ViewState["CommandArgument"] = value; }
    }

    protected override void OnChanged(RatingEventArgs e) {
        base.OnChanged(e);
        RaiseBubbleEvent(this, new CommandEventArgs(CommandName, CommandArgument));
    }

}

Then replace the old control with new one:

<pages>
  <tagMapping>
    <add tagType="AjaxControlToolkit.Rating, AjaxControlToolkit" mappedTagType="Sample.ExRating, Sample"/>
  </tagMapping>
</pages>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文