简体   繁体   English

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

[英]UpdatePanel with ASP.NET Repeater and Checkbox Aync Postback issue

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: 我无法触发我的CheckBox CheckedChange事件,或者捕获它或发生任何失败的事件:

ASPX Code 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>

The Code behind function "chk_handle_Changed" is never reached. 函数"chk_handle_Changed"后面的代码永远不会到达。 The Linkbutten works perfectly. Linkbutten完美运行。

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. 我认为您可能在每个回发上都重新绑定了转发器-我通过删除Page_Load()中的“ if(!IsPostBack)”语句对它进行了测试,并且能够重现您描述的有问题的行为。

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. 填充控件后,ViewState会处理它的数据,因此,除非数据发生更改,否则您不应该一直重新绑定它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM