How to use javascript to hide or show an ASP.Net control?

  • Thread starter Thread starter Nestor
  • Start date Start date
N

Nestor

Is this possible at all? I'm working on a Atlas project which at one point
requires me to hide an ASP.net control with Javascripts running on the
client side.

Anyone able to provide any help on this?

Thanks.
 
Unless I misunderstood the question, the following js should work:

document.getElementById( {ID of ASP.net control} ).style.display = 'none'.
 
Thanks, that worked pretty well.... if my control is initially not visible,
how do i get it to show on later? Seems like the javascript can't get the
object if the initial state is not visible?
 
try the style's setAttribute method,

hide:
....style.setAttribute('display', 'none')

show:
....style.setAttribute('display', '')

note: ''could be replaced with 'block', 'inline', etc.

fyi, "display: none" hides the element and collapses the area that it
occupied, "visibility: none" just hides the element.
 
one more thought. if the control is initially not visible because you set
the "Visible" property in the code-behind to false, then it is not possible
to show it using js. The reason is that asp.net will not generate any html
for controls where the "Visible" property is false. Instead, you should set
the control's style display attribute to 'none' in the code-behind.
 
Hi,

I'll add one more question: It seems some features of STYLE are not
supported everywhere, everytime. What can we do with that?

Afshar
 
You should set the style.display property of the HTML element that the
Control renders on the client, on the client. The code that you've been
given is server-side code.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
Back
Top