自动完成搜索框输入字段

ay鱼Ja

我正在使用JQuery与数据库自动完成搜索文本框。由于我使用的是html文本框,因此当我想访问查询字符串中的搜索文本框的文本时,会出现问题。要在上下文中使用它,要么我必须使用runat="server"要么可以使用,asp:Textbox但是在两种情况下,我的自动填充功能都无法正常工作。

这是aspx代码:

<div id="search-location-wrapper">
            <input type="text" id="txtSearch" class="autosuggest" />
            <div id="search-submit-container">
            <asp:Button ID="btnSearch" runat="server" Text="Search" 
                      onclick="btnSearch_Click"></asp:Button>
            </div>
</div>

C#代码:

protected void btnSearch_Click(object sender, EventArgs e)
    {
        string location = txtSearch.ToString();  /*Here is the error: txtSearch is not in current context */
        int id = Convert.ToInt32(ddlCategory.SelectedValue);
        string url = "SearchResults.aspx?Id="+id+"&location="+location;
        Response.Redirect(url);
    }
迈克·史密斯·德夫(MikeSmithDev)

您的问题很可能就是ASP.NET在将文本框放在其runat="server"时正在更改其ID 您的jQuery可能类似于:

$("#txtSearch")

而是将添加runat="server"到您的文本框中,然后将其更改为:

$("#<%= txtSearch.ClientID %>")

页面呈现后,它将为文本框放入正确的ID。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章