【发布时间】:2010-09-13 14:16:51
【问题描述】:
我的页面包含一个Repeater,它在数据可用时异步加载数据,使用UpdatePanel 来管理异步请求。
该页面包含一些类似这样的内容:
<asp:UpdatePanel ID="DataUpdatePanel" runat="server">
<ContentTemplate>
<table>
<asp:Repeater ID="RepeaterBlock" runat="server">
<HeaderTemplate><thead><tr><th>Name</th><th>Status</th><th class="empty"></th></tr></thead></HeaderTemplate>
<ItemTemplate><tr>
<td><a class="link" href="Detail.aspx?item=<%# DataBinder.Eval( Container.DataItem, "Name") %>"><%# DataBinder.Eval( Container.DataItem, "Name") %></a>
</td>
<td><%# DataBinder.Eval( Container.DataItem, "Status") %></td>
<td class="no-border">
[<asp:LinkButton CommandName='Schedule' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Name") %>' ID="ScheduleButton" runat="server" CausesValidation="false" >Schedule</asp:LinkButton>]
</td>
</tr></ItemTemplate>
</asp:Repeater>
</table>
</ContentTemplate>
</asp:UpdatePanel>
问题在于 LinkButton 似乎不会触发任何类型的回发 - 单击它并在代码隐藏中的事件侦听器上放置一个断点没有可见的响应,它永远不会被触发。
我尝试过像这样手动添加触发器:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ScheduleButton" />
</Triggers>
但不幸的是,因为控件在 ContentTemplate 中,如果我尝试这样做,它就会崩溃。
我探索的另一个途径是在代码隐藏中显式添加它们:
RepeatData.DataBind();
RepeatData.ItemCommand += new RepeaterCommandEventHandler(RepeatData_ItemCommand);
UpdateScripts.RegisterAsyncPostBackControl(FindControlRecursive( RepeatData, "SchedulButton"));
FindControlRecursive 方法的行为与 FindControl 类似,只是它实际上查找控件。
这不会崩溃,但也不会导致 LinkButtons 生效。
谁能建议我需要做什么才能让他们按照我的预期回复?
编辑:最初我让这个页面在没有 UpdatePanel 的情况下工作,它工作得很好,随着更多数据开始超时,所以我需要异步获取数据。正是在我进行此更改时,链接按钮停止工作。
【问题讨论】:
-
处理程序注册了什么事件?我没有在您的标记中看到任何指定。
-
它不在标记中 - 这就是为什么我将它添加到来自 CodeBehind 的 sn-p 第二行的中继器中。