如何通过TextBox控件触发UpdatePanel?
考虑以下代码:
<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 语句来“伪造”它。我想知道......一定有更好的方法......对吧!?
Consider the following code:
<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>
The button will trigger an update of the panel. I wanted to trigger an update by a keydown of the search field, so I'm 'faking' it with a jQuery statement that clicks the button. I'm wondering... there must be a better way... right!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行此操作来刷新 updatepanel,而无需按钮:
您只需为 updatepanel 提供一个 ID(此处为 updatePanel),然后
在按键时或在您准备好时执行该代码。
You can do this to refresh your updatepanel without the button:
You just need to give your updatepanel an ID (updatePanel here)
Execute that code on a keyup or whenever you are ready for it.
该链接有点过时,但应该几乎可以满足您的要求:
http:// remy.supertext.ch/2007/06/see-search-results-as-you-type-an-aspnet-ajax-control/
The link is a bit outdates, but should pretty much do what you want:
http://remy.supertext.ch/2007/06/see-search-results-as-you-type-an-aspnet-ajax-control/