ASP.NET jQuery的自动完成 - 文本第一次搜索后没有响应 [英] ASP.NET jQuery AutoComplete - textbox not responding after first search

查看:155
本文介绍了ASP.NET jQuery的自动完成 - 文本第一次搜索后没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我没有找到在本网站上的其他问题同样的问题。下面是我遇到:

So far I'm not finding the same problem in other questions on this site. Here's what I'm experiencing:

我有含在那里我有一个ASP一个搜索区域一个UpdatePanel的ASP.NET应用程序的WebForms:我使用一个jQuery自动完成文本框

I have an ASP.NET WebForms app with an UpdatePanel containing a search area where I have a ASP:TextBox that I use for a jQuery autocomplete.

$(document).ready(function() {
    $("#tabContainer_tabSearchBreaks_txtSearchName").autocomplete("AutoCompleteEmployee.ashx", { minChars: 3, maxItemsToShow: 10 });
});

这整个事情工作正常,但如果我点击一个ASP:巴顿和处理一些code的搜索区域,自动完成的JavaScript不再作品

This whole thing works fine, but if I click on a ASP:Button and process some code for the search area, the autocomplete javascript no longer works.

任何想法???

有一定是重置文本框调用JS code的解决方案。

There's got to be a solution to reset the textbox to call the js code.

[更新 - 更多code]
这里的更新按钮做什么,它是从自动完成code分离搜索区域:

[Update - More Code] Here's what the update button does for the search area that is separate from the autocomplete code:

 try {
     int employeeID;
     string[] namelst = txtSearchName.Text.Split(new string[] {
         " "
     }, StringSplitOptions.None);
     employeeID = int.Parse(namelst[2].Substring(1, namelst[2].Length - 2));
     string name = namelst[0] + " " + namelst[1];
     var breaks = bh.ListBreaksForEmployeeByDate(employeeID, DateTime.Parse(txtFromDate.Text), txtToDate.Text.Length > 0 ? DateTime.Parse(txtToDate.Text).AddDays(1).AddSeconds(-1) : DateTime.Today.AddDays(1).AddSeconds(-1));

     if (breaks.Count() > 0) {
         lblEmployeeTitle.Text = "Breaks for " + name;
         gridSearchBreaks.DataSource = breaks;
         gridSearchBreaks.DataBind();
     }
 } catch {}

希望这有助于。暂时我已经隐藏包含此问题,从用户的选项卡。

Hope this helps. For the time being I've hidden the tab that contains this problem from the users.

推荐答案

我觉得您遇到的经典问题ASP.NET UpdatePanel控件和jQuery。问题是这样的:jQuery的code(在你的情况下,它是自动完成的,但它可以是任何东西),在页面加载工作正常,但它停止了部分回发后工作。如果是这样的情况下,有几件事情你需要了解使用jQuery与UpdatePanel控件。

I think you're experiencing a classic problem with ASP.NET UpdatePanel controls and jQuery. The problem is the following: jQuery code (in your case it's auto-complete, but it can be anything) works fine on the page load, but it stops working after a partial postback. If this is the case, there is a couple of things you need to understand about using jQuery with UpdatePanel controls.

首先,在$(文件)中定义的所有事件绑定。就绪停止第一个部分回发后工作(我假设你按一下按钮导致部分回发)。这仅仅是ASP.NET的工作方式。那么,你如何解决这个问题?那么,有几种方法来解决这个问题。一个典型的建议是与ASP.NET AJAX本身的页面加载事件。就绪替换为$(文件)。这样可以解决一个问题,但它很可能会导致更多的问题,因为现在你将在每一个局部回传导致事件处理程序的重复执行单一事件绑定的事件。你可以通过调用解决一些问题的取消绑定作为执行任何绑定在你的选择。对于简单的事件绑定,您可以继续使用$(文件)。就绪与在生活功能(而不是点击,悬停等)。

First, all event bindings defined in $(document).ready stop working after the first partial postback (and I assume that your button click causes a partial postback). This is just the way ASP.NET works. So how do you fix it? Well, there are several ways to address this problem. A typical recommendation is to substitute $(document).ready with the ASP.NET AJAX's own pageLoad event. This may solve one problem, but it will most likely cause more issues because now you will be binding events on every partial postback causing repeated execution of event handlers on a single event. You can address some issues by calling unbind for your selector before performing any bindings. For simple event bindings, you can keep using $(document).ready with the live function (instead of click, hover, etc).

我没有使用jQuery插件与UpdatePanel的,所以我不能肯定你需要做什么说什么,但一旦你明白发生了什么,它不应该是很难找到正确的方法。要了解更多关于这个问题,可能的解决方案,请阅读大卫沃德的文章<一个href=\"http://encosia.com/2009/03/25/document-ready-and-pageload-are-not-the-same/\">$(document).ready()和页面加载()是不一样的!(本文包括几个例子)。

I haven't used jQuery plugins with UpdatePanel, so I can't say for sure what you need to do, but once you understand what is happening, it should not be hard to find the right approach. To learn more about this problem and possible solutions, please read Dave Ward's article $(document).ready() and pageLoad() are not the same! (the article includes several examples).

这篇关于ASP.NET jQuery的自动完成 - 文本第一次搜索后没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆