简体   繁体   English

访问不可见属性

[英]Access invisible property

Please see the code below: 请参见下面的代码:

<%@ 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>

The asp.net text boxes (txtusername and txtterminalip) must be visible for this to work. asp.net文本框(txtusername和txtterminalip)必须可见才能起作用。 Are there any controls I can use that are invisible? 我可以使用任何不可见的控件吗? ie I do not want to display the username and IP address on the webpage. 即我不想在网页上显示用户名和IP地址。

Use css display:none; 使用css display:none;

Dirty sample 脏样品

<div>
    <asp:TextBox ID="txtUserName" runat="server" style="display:none;"></asp:TextBox>
    <asp:TextBox ID="txtTerminalIP" runat="server" style="display:none;"></asp:TextBox>
</div>

Better sample 更好的样本

<div class="i_want_to_hide">
    <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
    <asp:TextBox ID="txtTerminalIP" runat="server"></asp:TextBox>
</div>

css 的CSS

.i_want_to_hide > input {
    display: none;
}

Simply use HiddenField 只需使用HiddenField

Represents a hidden field used to store a non-displayed value. 表示用于存储非显示值的隐藏字段。

Example Usage: 用法示例:

<asp:HiddenField ID="txtUserName" Value="YourValue" />
<asp:HiddenField ID="txtTerminalIP" Value="YourValue" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM