Skip navigation

Monthly Archives: April 2009

If we want to make a control invisible in asp.net, may be the most straight forward way is to set the Visible property to “false”. As long as we are accessing this control from server side, there is no problem. However, if we need to access it from client side using JavaScript, then we have a problem. Once we make the control invisible by setting the Visible property to “false”, we will no longer be able to access it from client side using JavaScript and we will not find the control using document.getElementById(“controlID”).

Solution to this problem is to use the style property to make it invisible. Here are some considerations as well. By using style, we can make a control invisible in two ways.

  1. using visibility:hidden
  2. using display:none

By using any one of the above 2 ways we can still access a control by using document.getElementById(“controlID”) but if we use visibility:hidden, the control will still occupy the space. On the other hand, the control will not occupy space if “display:none” is used.

Making a button coltrol invisible using style

To make a control invisible from aspx page the following code can be used

Setting display style from aspx page

Setting display style from aspx page

To make a control invisible from cs page the following code can be used

setting display style from cs file

setting display style from cs file

Advertisements