これは私の .aspx ページのコードで、テキストボックスにオートコンプリートを使用しています。
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Preferences.aspx/GetAutoCompleteData",
data: "{'Name':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<table style="width:auto">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Please Type Student Name:"></asp:Label>
</td>
<td>
<input type="text" id="txtSearch" class="autosuggest" />
<asp:TextBox ID="TextBox1" runat="server" Text=txtsearch Visible="true" class="autosuggest"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</td>
</tr>
</table>
runat="Server" を入れると
<input type="text" id="txtSearch" class="autosuggest" />
その後、オートコンプリートは機能しません。フォームタグはマスターページで使用されます。
コントロールの名前プロパティを使用して解決された問題
ソースコード:
<input type="text" name="_name" />
<asp:Button ID="btnShow" runat="server" Text="Show" onclick="btnShow_Click" />
分離コード:
protected void btnShow_Click(object sender, EventArgs e)
{
string strValue = Page.Request.Form["_name"].ToString();
Response.Write(strValue);
}
参照: http://www.etechpulse.com/2013/02/get-html-input-controls-value-server.html
助けてくれてありがとう。