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

时间:2011-06-17 09:39:18

标签: c# asp.net

我的asp.net Web应用程序中有一个按钮。当我单击按钮时,它将隐藏相同的Web应用程序中的文本框。 如果有人可能帮助我它非常有用 谢谢

4 个答案:

答案 0 :(得分:2)

如果按钮是html按钮,那么你可以使用javascript来执行此操作:

点击js后按钮调用:

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

document.getElementById(textBoxId).style.visibility = "hidden";

答案 1 :(得分:1)

你可以用JQuery做到这一点:

<script>
    $("#myButton").click(function () {
      $("#myTextBox").hide("slow");
    });    
</script>

答案 2 :(得分:1)

来自TextBoxId.Visible = false;

后面的代码 来自Javascript document.getElementById('<%=TextBoxId.ClientId%>').style.dispaly="none";

答案 3 :(得分:0)

这就是你要找的东西:

<强> HideTextBox.aspx

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

文件背后的代码 的 HideTextBox.aspx.cs

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;

        }
    }
}