2011-06-17 88 views
-3

我的asp.net web應用程序中有一個按鈕。當我點擊該按鈕時,它將隱藏相同網絡應用程序中的文本框。 如果是有可能,任何人都幫我了非常有用的 謝謝單擊asp.net網站中的按鈕時隱藏文本框

+0

檢查按鈕onclick事件處理程序,你可以在這裏傳遞代碼隱藏嗎? – Khodor 2011-06-17 09:41:23

+0

你想躲在後面的代碼 – 2011-06-17 09:42:13

+0

在問問題之前先做谷歌吧! – 2011-06-17 09:43:42

回答

1

從後面TextBoxId.Visible = false;

代碼從Javascript document.getElementById('<%=TextBoxId.ClientId%>').style.dispaly="none";

2

如果按鈕是一個html按鈕,然後就可以使用JavaScript來做到這一點:

以下按鈕調用的onclick JS:

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

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

這樣會工作,如果回帖發生.. ?? – 2011-06-17 09:43:03

+0

Actully我不認爲這會工作,如果我回來...... – 2011-06-17 09:45:29

+0

@Pranay:你爲什麼這麼想? – 2011-06-17 09:46:32

1

您可以用jQuery做到這一點:

<script> 
    $("#myButton").click(function() { 
     $("#myTextBox").hide("slow"); 
    });  
</script> 
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; 

     } 
    } 
} 
相關問題