简体   繁体   English

在ASP.Net中使用jQuery AutoComplete插件-自动完成时提交

[英]Using jQuery AutoComplete Plugin in ASP.Net - Submit on autocomplete

Hi I'm using jQuery AutoComplete Plugin in ASP.Net as outlined in the article below, so that as a user types in a .Net textbox they get a list of options to choose them. 嗨,我在ASP.Net中使用了jQuery AutoComplete插件,如下面的文章所述,因此,当用户在.Net文本框中键入内容时,他们会获得选择选项的列表。 This works fine, but what I need to do now is call a server side function when the user has finished typing or has choosen a value, rather than the user having to submit the value by pressing a button. 这可以正常工作,但是我现在需要做的是在用户完成键入或选择一个值后调用服务器端函数,而不是用户必须通过按下按钮来提交值。

any suggestions for the best way of doing this? 有什么建议最好的方法吗?

Thanks for your help! 谢谢你的帮助!

http://www.aspsnippets.com/Articles/Using-jQuery-AutoComplete-Plugin-in-ASP.Net.aspx http://www.aspsnippets.com/Articles/Using-jQuery-AutoComplete-Plugin-in-ASP.Net.aspx

Depends what kind of server-side action you need to perform. 取决于您需要执行哪种服务器端操作。 If you simply want to submit your form, that's a jQuery one-liner in response to the jQuery.autocomplete's result event: 如果您只想提交表单,那么这是对jQuery.autocomplete的result事件的一种jQuery响应:

$('input#suggest').result(function(event, data, formatted) {
   $("#myform").submit();
});

If you want to perform an asynchronous call to a specific method, you should look into $.ajax in jQuery. 如果要对特定方法执行异步调用,则应在jQuery中查看$ .ajax On the server side you have a slew of possibilities - you can setup your function as a generic HTTP handler, a JSON web service, or an ASP.NET Page Method, all of which can be called using AJAX. 在服务器端,有很多可能性-您可以将函数设置为通用HTTP处理程序,JSON Web服务或ASP.NET页面方法,所有这些都可以使用AJAX调用。

If you can provide more information what you need to achieve (as comment to my answer), I can provide more details. 如果您可以提供更多信息(需要回答的问题),我可以提供更多详细信息。

Edit: Using the details provided in comments, I believe in your case you can use your control's ClientID as follows: 编辑:使用注释中提供的详细信息,我相信在您的情况下,您可以如下使用控件的ClientID

var selector = '#<%= searchTB.ClientID %>';
$(selector).result(function(event, data, formatted) {
   CustomSubmit();
});

In which case the javascript needs to be in-lined in the .aspx document, ie cannot be in an external .js file. 在这种情况下,需要在.aspx文档中内联javascript,即不能在外部.js文件中。

$(document).ready(function() { $("#<%=searchTB.ClientID%>").autocomplete('Search_VB.ashx'); $(document).ready(function(){$(“#<%= searchTB.ClientID%>”)。autocomplete('Search_VB.ashx');

        var selector = '#<%=searchTB.ClientID%>';
        $(selector).result(function(event, data, formatted) {
           CustomSubmit();
        });

    });  

for anyone looking to add this to the code from the originally stated article, above this how it's done (and called the Javascript function CustomSubmit()) 对于希望将其添加到原始声明的文章中的代码的人,在此之上是如何完成的(并称为Javascript函数CustomSubmit())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM