我想设置输入标签类型=" text"为无形/可见在按钮上单击事件,使用runat =" server"
以下是编码
$(document).ready(function () {
SearchText();
});
function SearchText()
{
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CalenderDetails.aspx/GetAutoCompleteData",
data: "{'Col3':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
</script>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<br />
<input type="text" id="txtSearch" class="autosuggest" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:GridView ID="Gr
idView1" runat="server" AllowPaging="True" PageSize="20" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound">
<HeaderStyle BackColor="#FFCC99" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
代码
[WebMethod]
public static List<string> GetAutoCompleteData(string Col3)
{
List<string> result = new List<string>();
if ((dtClone != null) && (dtClone.Rows.Count > 0))
{
DataRow[] foundRows;
string expression = "Col3 LIKE '%" + Col3 + "%'";
// Use the Select method to find all rows matching the filter.
foundRows = dtClone.Select(expression);
for (int i = 0; i < foundRows.Length; i++)
result.Add(foundRows[i][2].ToString());
}
return result;
}
如果我使用runat =" server",我可以使其可见/看不见,但是Ajax调用将无法执行搜索操作
任何身体都可以告诉如何克服这个问题吗?
您很难让两件事一起工作,即runat="server"
并在同一textbox
上制作ajax call
。
您可以使用不会更改文本框的ID的ClientIDMode="Static"
,您将能够发送AJAX调用。
<asp:TextBox ID="txtSearch" ClientIDMode="Static" runat="server"></asp:TextBox>
您可以使用jQuery并使用以下代码
function clicked(){
console.log("sf"+$("#grand").css("visibility"))
if($("#grand").css("visibility")=="visible"){
$("#grand").css("visibility","hidden");
}
else{
$("#grand").css("visibility","visible");
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="hello" id="grand">
<input type="button" value="hide/show" onclick="clicked()">
首先,如果您真的不想将runat =" server"添加到按钮。
是正确的,您可以将Web方法应用于服务器端,
在客户端,您可以应用Ajax调用您的Web方法。
要实现在服务器端隐藏HTML控件的
您可以尝试通过将其添加到Web方法来尝试应用ScriptManager和jQuery。
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "clientScript", "$(':text').toggle()", true);
如果隐藏/显示type =" text"没有条件,则可以使用切换。
否则,您可以实施所需的条件并致电
$(':text').show()
或
$(':text').hide()
用于显示和将您的控件隐藏在表单上。