单击某个项目时如何让 AutoCompleteExtender 提交
我的 ASP.net 表单上有一个文本框和一个按钮,用于执行搜索。我从 AJAX 工具包添加了一个 autocompleteextender,以便在用户键入时显示建议。这工作正常,但是我想要发生的是当用户在显示的建议列表中选择一个项目时触发按钮的 Click 事件。有人知道如何做到这一点吗?
I have a textbox and a button on my ASP.net form for executing a search. I have added an autocompleteextender from the AJAX toolkit to show suggestions while the user is typing. This works fine, however what I want to happen is for the Click event of the button to fire when the user selects an item in the displayed list of suggestions. Anyone any idea how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于项目选择事件将触发客户端 JavaScript 事件,因此我通常将以下代码添加到 OnClientItemSelected 事件方法中:
您需要相应地找到按钮的正确名称并将其替换到上面。
作为一项附加功能,有时我希望能够在“自动完成”中输入一个值,如果我知道我想要什么,就立即按回车键。为了实现这一点,您需要将自动完成文本框和按钮包装在面板中,并相应地设置默认按钮:
Since the item selected event is going to fire a client side JavaScript event, I typically add the following code to my OnClientItemSelected event method:
You'll need to find the proper name of your button accordingly and replace it above.
As an added feature, sometimes I want to be able to type a value in to the AutoComplete and hit the enter key right away if I know what I want. To accomplish this, you'll want to wrap your AutoComplete textbox and button in a panel and set the default button accordingly:
将文本框的 Autopostback 设置为 true。
然后创建一个 onTextChanged 事件处理程序来执行与按钮相同的操作。或者您可以将其指向按钮所具有的相同事件处理程序
Set the textbox's Autopostback to true.
Then create an onTextChanged event handler to do the same thing as your button. Or you could just point it to the same event handler your button has
看看 onclientitemselected
这里有一些信息:
使用 AutoCompleteExtender 控件实现自动建议
Have a look at onclientitemselected
There is some info here:
Implementing Auto-Suggest Using AutoCompleteExtender Control