请参阅以下代码:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="WebApplication2.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
<script type = "text/javascript">
function GetSQLTable() {
$.ajax({
type: "POST",
url: "WebForm2.aspx/GetSQLTable",
data: '{username: "' + $("#<%=txtUserName.ClientID%>")[0].value + '", terminalip: "' + $("#<%=txtTerminalIP.ClientID%>")[0].value + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
window.onload = GetSQLTable
</script>
</head>
<body style = "font-family:Arial; font-size:10pt">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtUserName" runat="server" visible="True"></asp:TextBox>
<asp:TextBox ID="txtTerminalIP" runat="server" visible="True"></asp:TextBox>
</div>
</form>
</body>
</html>
必须显示asp.net文本框(txtusername和txtterminalip)才能使其正常工作。我可以使用任何看不见的控件吗?即我不想在网页上显示用户名和IP地址。
答案 0 :(得分:0)
使用css display:none;
<div>
<asp:TextBox ID="txtUserName" runat="server" style="display:none;"></asp:TextBox>
<asp:TextBox ID="txtTerminalIP" runat="server" style="display:none;"></asp:TextBox>
</div>
<div class="i_want_to_hide">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<asp:TextBox ID="txtTerminalIP" runat="server"></asp:TextBox>
</div>
.i_want_to_hide > input {
display: none;
}
答案 1 :(得分:0)
只需使用HiddenField
即可表示用于存储未显示值的隐藏字段。
示例用法:
<asp:HiddenField ID="txtUserName" Value="YourValue" />
<asp:HiddenField ID="txtTerminalIP" Value="YourValue" />