在内容占位符中使用文本框时,为什么Textbox中的自动完成jquery无法正常工作? - c#

在我的Web表单上,我正在文本框中使用自动完成的Jquery。当我在普通HTML页面中(即在title标签下和head标签中)使用此Jquery时,它工作正常,但在contentplaceholder中使用时,此Jquery无法工作。
这是我的aspx页面-

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <script type="text/javascript">
      $(function () {
      var items=[<%=autotag %>];
      $("TextBox1").autocomplete({
      source:items
      });
      });
  </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table width="97%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td><asp:TextBox ID="TextBox1" runat="server" Width="150px" AutoPostBack="True" 
        ontextchanged="TextBox1_TextChanged"></asp:TextBox></td></tr>
</table>
</asp:Content>

这是我正常的html页面-

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <script type="text/javascript">
      $(function () {
      var items=[<%=autotag %>];
      $("#TextBox1").autocomplete({
      source:items
      });
      });
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>Name:</td>
    <td>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" 
            ontextchanged="TextBox1_TextChanged"></asp:TextBox></td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>

这是我的CS页面-

public void bind1()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);
        con.Open();
        string query = "select name from tbl_names where name like '" + TextBox1.Text + "'+'%'";
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        while (dr.Read())
        {
            if (string.IsNullOrEmpty(autotag))
            {
                //autotag += "\"" + dr["name"].ToString() + "\"";
                autotag += "\"" + dr["name"].ToString() + "\"";
            }
            else
            {
                //autotag += ", \"" + dr["name"].ToString() + "\"";
                autotag += ", \"" + dr["name"].ToString() + "\"";
            }
        }
    }

请指导我为什么我的自动完成jquery在contentplaceholder中不起作用。请指导我我做错了什么?

参考方案

ClientIDMode设置为Static,因为asp.net更改了渲染控件的ID:

<asp:TextBox ID="TextBox1" runat="server" Width="150px" AutoPostBack="True" 
        ontextchanged="TextBox1_TextChanged" ClientIDMode="Static"></asp:TextBox>

或者如果您不想这样做,则在客户端代码中使用控件的ClientID属性,例如:

var textBox1 = "<%=this.TextBox1.ClientID %>";
$("#"+textBox1).autocomplete({
  source:items
});

jQuery不起作用 - php

我正在使用带有ajax的jquery。有时,给出错误$未定义。这是我的代码:<script language="javascript" type="text/javascript"> var base_path="<? echo $this->baseUrl().'/…

Div单击与单选按钮相同吗? - php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” - php

我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…

CodeIgniter更新查询被执行两次 - php

我正在使用CodeIgniter 2.2。每次访问页面时,我都必须用+1更新数据库。代码可以工作,但是每次都会增加+2。示例:如果是total views=2,则在单击页面后total views应该是3,但是数据库中的值是4。我确定我在控制器中仅调用一次模型add_one_to_view_image。控制者 function view(){ $view_i…

jQuery Ajax文件上传在客户端浏览器上无法正常工作 - javascript

我正在尝试使用Ajax和JQuery实现个人资料图片上传功能我能够将个人资料图片成功上传到我尝试过的所有机器和移动设备上的数据库中。它适用于我在Chrome,Edge,Firefox,Safari甚至Vivaldi上使用。问题是我住在加拿大的客户无法将他们的个人资料图片上传到数据库。另外,纵向宽高比的图像倾向于向侧面旋转。我一直在要求他重​​新注册并多次提供…