javascript - jquery 自动完成文本框不适用于使用 ASP.NET 的更新面板

标签 javascript c# jquery asp.net

卸载 jquery 后无法获取结果更新面板如何重新加载。如何使用更新面板克服 jquery

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TPAppl.WebForm1" %>

<!doctype html>
<html lang="en">
  <head>
      <meta charset="utf-8">
      <title>jQuery UI Autocomplete - Custom data and display</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
      <script src="http://code.jquery.com/jquery-1.11.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


     <script type="text/javascript">
    $(function () {
        initializer();
    });


    var prmInstance = Sys.WebForms.PageRequestManager.getInstance();


    prmInstance.add_endRequest(function () {
        //you need to re-bind your jquery events here
        initializer();
    });
    function initializer() {
        var projects = [
{ "label": "AN-01", "actor": "Port Blair " },
{ "label": "AN-02", "actor": "Car Nicobar " }
        ];

        $("#lstRTO").autocomplete({
            source: projects,
            select: function (event, ui) {
                $("#lstRTO").val(ui.item.label);
                return false;
            }
        })
        .autocomplete("instance")._renderItem = function (ul, item) {
            return $("<li>")
              .append("<a><strong>" + item.label + "</strong> / " + item.actor + "</a>")
              .appendTo(ul);
        };


    }


</script>
</head>
 <body runat="server">
      <form runat="server">
       <asp:ScriptManager ID="ScriptManager1" runat="server">     </asp:ScriptManager>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
              <ContentTemplate>
               <asp:TextBox ID="TextBox1" AutoPostBack="true"  runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
              <input id="lstRTO">
          </ContentTemplate>
       </asp:UpdatePanel>
   </form>
</body>

C# 代码类似

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TPAppl
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            TextBox1.Text = TextBox1.Text+"123";
        }
    }
}

最佳答案

更改您编写文本框 id 的方式

来自:

 $("#lstRTO").autocomplete({

收件人:

 $("[id*=lstRTO]").autocomplete({

它将 100% 有效。

关于javascript - jquery 自动完成文本框不适用于使用 ASP.NET 的更新面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30755104/

相关文章:

php - like 运算符在 oracle 数据库中不起作用

javascript - 将参数传递给 Javascript/NodeJ 中的预定义回调

javascript - 记住 Kendo-UI 中刷新时扩展的细节网格

c# - 将数组添加到具有有限列的数据表中

c# - 为什么在比较两个可空值是否相等时不使用短路逻辑 'and' 运算符?

javascript - 在 JQuery/Javascript 中检索原始样式表 CSS 属性值

javascript - 为什么当值为 false(它是 bool 值)时我无法传递过滤后的数据

javascript - 页面的打印版本。我想附加相关链接的完整网址

c# - 在render事件中获取某个div的html代码

jquery - 仅通过变量名引用 jQuery 对象(moSTLy DOM 对象)还是通过 $ 更快?