Hiding the text box when clicking the button in the asp.net website
I have a button in my asp.net web application. When i clicking the button it will hide t开发者_如何学编程he text box in the same webs application . If is it possible that anyone help me its very useful Thank you
If the button is an html button then you can use javascript to do this:
onclick of button call following js:
document.getElementById(textBoxId).style.display = "none";
or
document.getElementById(textBoxId).style.visibility = "hidden";
from code behind TextBoxId.Visible = false;
from Javascript document.getElementById('<%=TextBoxId.ClientId%>').style.dispaly="none";
You can do it with JQuery:
<script>
$("#myButton").click(function () {
$("#myTextBox").hide("slow");
});
</script>
This is what you are looking for:
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>
And the code behind file 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;
}
}
}
精彩评论