データベースで検索テキストボックスをオートコンプリートするために 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);
}