Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net网站中单击按钮时隐藏文本框_C#_Asp.net - Fatal编程技术网

C# 在asp.net网站中单击按钮时隐藏文本框

C# 在asp.net网站中单击按钮时隐藏文本框,c#,asp.net,C#,Asp.net,我的asp.net web应用程序中有一个按钮。当我点击该按钮时,它将隐藏同一Web应用程序中的文本框。 如果有人能帮助我,那很有用 谢谢如果按钮是html按钮,则可以使用javascript执行此操作: 单击下面的按钮调用: document.getElementById(textBoxId).style.display = "none"; 或 您可以使用JQuery执行此操作: <script> $("#myButton").click(function () {

我的asp.net web应用程序中有一个按钮。当我点击该按钮时,它将隐藏同一Web应用程序中的文本框。 如果有人能帮助我,那很有用
谢谢

如果按钮是html按钮,则可以使用javascript执行此操作:

单击下面的按钮调用:

document.getElementById(textBoxId).style.display = "none";


您可以使用JQuery执行此操作:

<script>
    $("#myButton").click(function () {
      $("#myTextBox").hide("slow");
    });    
</script>
来自TextBoxId.Visible后面的代码=false


来自Javascript文档.getElementById.style.dispaly=none

这就是您要寻找的:

HideTextBox.aspx


检查按钮onclick的事件处理程序,你能在这里传递隐藏的代码吗?你想隐藏隐藏的代码吗?在问问题之前先做谷歌…。因为在服务器端,文本框可见的代码属性仍然是true@Pranay:当我们这样做时,此文本框将用作隐藏字段,提交后,如果我们发回,它将处于初始状态,最有可能是看得见的
<script>
    $("#myButton").click(function () {
      $("#myTextBox").hide("slow");
    });    
</script>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HideTextBox.aspx.cs" Inherits="HideTextFields" %>

<!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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="BtnHide" runat="server" onclick="Button1_Click" 
        Text="Hide TextBox" />   
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class HideTextFields : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (Control c in form1.Controls)
        {
            if (c is TextBox)
                c.Visible = false;

        }
    }
}