UpdatePanel 与 ASP.NET Repeater 和 Checkbox Aync 回发问题

发布于 2024-07-19 03:38:03 字数 1257 浏览 1 评论 0原文

我这里有一个相当烦人的问题,

我无法触发我的 CheckBox CheckedChange 事件,也无法捕获或失败的任何内容:

ASPX 代码

<asp:UpdatePanel runat="server" ID="udp_Lists" UpdateMode="Always">
<ContentTemplate>
    <asp:Repeater ID="rep_showings" runat="server">
        <HeaderTemplate>
        </HeaderTemplate>
        <ItemTemplate>
            <div class="div_assignment">
                <div class="div_assignment_text">
                    <asp:LinkButton runat="server" ID="lnk_show_task" OnClick="lnk_show_task_Click" CommandArgument='<%# Eval("Id") %>' Text='<%# Eval("TaskTitle") %>'></asp:LinkButton>
                </div>
                <div class="div_assignment_checkbox">
                    <asp:CheckBox runat="server" ID="chk_handle" AutoPostBack="true" OnCheckedChanged="chk_handle_Changed" ToolTip='<%# Eval("Id") %>' />
                </div>
            </div>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
    </asp:Repeater>
</ContentTemplate>
<Triggers>
</Triggers>

函数 "chk_handle_Changed" 背后的代码永远不会到达。 Linkbutten 工作完美。

I have a rather annoying issue here

I can't get my CheckBox CheckedChange event to fire, or catch or whatever it is that fails:

ASPX Code

<asp:UpdatePanel runat="server" ID="udp_Lists" UpdateMode="Always">
<ContentTemplate>
    <asp:Repeater ID="rep_showings" runat="server">
        <HeaderTemplate>
        </HeaderTemplate>
        <ItemTemplate>
            <div class="div_assignment">
                <div class="div_assignment_text">
                    <asp:LinkButton runat="server" ID="lnk_show_task" OnClick="lnk_show_task_Click" CommandArgument='<%# Eval("Id") %>' Text='<%# Eval("TaskTitle") %>'></asp:LinkButton>
                </div>
                <div class="div_assignment_checkbox">
                    <asp:CheckBox runat="server" ID="chk_handle" AutoPostBack="true" OnCheckedChanged="chk_handle_Changed" ToolTip='<%# Eval("Id") %>' />
                </div>
            </div>
        </ItemTemplate>
        <FooterTemplate>
        </FooterTemplate>
    </asp:Repeater>
</ContentTemplate>
<Triggers>
</Triggers>

The Code behind function "chk_handle_Changed" is never reached.
The Linkbutten works perfectly.

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

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

发布评论

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

评论(1

野稚 2024-07-26 03:38:03

我看了你的问题。 我使用了以下代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        this.rep_showings.DataSource = new object[] { new { Title = "title", ID = "id" } };
        this.rep_showings.DataBind();
    }
}

protected void chk_handle_Changed(object source, EventArgs e)
{
    Trace.Write("here");
}

protected void lnk_show_task_Click(object source, EventArgs e)
{
    Trace.Write("here 2");
}

protected void rep_showings_ItemCommand(object source, RepeaterCommandEventArgs e)
{ }

上面的代码有效。 我认为您可能在每次回发时重新绑定转发器 - 我通过删除 Page_Load() 中的“if (!IsPostBack)”语句对此进行了测试,并且我能够重现您描述的有问题的行为。

如果可能,应避免在每次回发时重新绑定控件。 填充控件后,它的数据将由 ViewState 处理,因此除非数据发生更改,否则您可能不应该一直重新绑定它。

I took a look at your problem. I used the following code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        this.rep_showings.DataSource = new object[] { new { Title = "title", ID = "id" } };
        this.rep_showings.DataBind();
    }
}

protected void chk_handle_Changed(object source, EventArgs e)
{
    Trace.Write("here");
}

protected void lnk_show_task_Click(object source, EventArgs e)
{
    Trace.Write("here 2");
}

protected void rep_showings_ItemCommand(object source, RepeaterCommandEventArgs e)
{ }

The above code works. I think you are probably re-binding your repeater on every postback - I tested this by removing the "if (!IsPostBack)" statement in Page_Load(), and I was able to reproduce the problematic behaviour you describe.

Rebinding a control on every postback should be avoided if possible. Once a control is populated, it's data is taken care of by ViewState, so unless the data is changing, you should probably not be rebinding it all the time.

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