如何触发一个UpdatePanel由一个TextBox控件? [英] How to trigger an UpdatePanel by a TextBox control?
本文介绍了如何触发一个UpdatePanel由一个TextBox控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下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>
,按钮将触发面板的更新。我希望通过搜索领域的的keydown触发更新,所以我'伪造'与单击按钮jQuery的声明中。我想知道......必须有一个更好的办法......好吧!?
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!?
推荐答案
您可以做到这一点,以刷新的UpdatePanel没有按钮:
You can do this to refresh your updatepanel without the button:
<script type="text/javascript">
function refreshPanel() {
__doPostBack('<%= updatePanel.UniqueID %>', '');
}
</script>
<label>Search:</label>
<asp:TextBox runat="server" ID="search"
ClientIDMode="Static" OnKeyUp="refreshPanel();" />
<asp:UpdatePanel runat="server" ID="updatePanel">
您只需要给你的UpdatePanel一个ID(这里的UpdatePanel)
You just need to give your updatepanel an ID (updatePanel here)
执行了code在KEYUP或当你已经准备好了。
Execute that code on a keyup or whenever you are ready for it.
这篇关于如何触发一个UpdatePanel由一个TextBox控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文