【发布时间】:2012-01-05 03:44:43
【问题描述】:
考虑以下代码:
<label>Search:</label><asp:TextBox runat="server" ID="search" ClientIDMode="Static" OnKeyUp="$('#searchButton').click();" /><asp:Button runat="server" ID="searchButton" ClientIDMode="Static" />
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView runat="server" DataSourceID="EntityDataSource1"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="true" PageSize="20"
Width="400" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="searchButton" />
</Triggers>
</asp:UpdatePanel>
该按钮将触发面板的更新。我想通过搜索字段的按键触发更新,所以我用点击按钮的 jQuery 语句来“伪造”它。我在想……一定有更好的方法……对吧!?
【问题讨论】:
-
@Kiran 搜索字段位于更新面板之外,这使得问题 1009086 完全不同,因为如果我使用自动提交,页面将被提交。也许 Remy 是对的,我应该为它编写自己的控件吗...
-
是的,我也同意。因为我现在也在做同样的事情,这可能是他的权利。
-
@KeesC.Bakker,因此我认为假装点击触发器没有任何问题。 UpdatePanel 模型通过捕获表单提交来工作——根据有效提交触发器维护的地图检查导致提交的元素。除非您想依赖 IMO 的 UpdatePanel 的内部工作,否则伪造触发点击似乎是一个不错的非侵入式解决方案。
标签: asp.net ajax triggers updatepanel ajax.net