본문 바로가기
개발언어

How to make controls visible false using javascript?

by 엔돌슨 2008. 5. 5.
반응형

동적으로 Textbox를 생성하고 특정값을 보관하고 있다가
쓰려니깐 Textbox가 보인다.

숨길수 없을까?
javascript 로 숨길수 있다.

http://www.daniweb.com/forums/thread86493.html

여기를 참고하였다 ^^
There are many ways to show/hide, render/not render a control
For ASP.NET webcontrols you have the Visible property which can be set to true or false but that's serverside.

For client side you have visibility attribute in CSS which can be "visible" or "hidden", here is an example:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlVisibilityClientSide.aspx.cs" Inherits="ControlVisibilityClientSide" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>ControlVisibilityClientSide</title>
  8.     <script type="text/javascript">
  9.         function toggleVisibility(controlId)
  10.         {
  11.             var control = document.getElementById(controlId);
  12.             if(control.style.visibility == "visible" || control.style.visibility == "")
  13.                 control.style.visibility = "hidden";
  14.             else
  15.                 control.style.visibility = "visible";
  16.  
  17.         }
  18.     </script>
  19. </head>
  20. <body>
  21.     <form id="form1" runat="server">
  22.     <div>
  23.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  24.         <input type="button" ID="btnShowHide" value="Show/Hide" onclick="toggleVisibility('TextBox1');" /></div>
  25.     </form>
  26. </body>
  27. </html>