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

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.
 
G

GSL

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

document.getElementById( {ID of ASP.net control} ).style.display = 'none'.
 
N

Nestor

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?
 
G

GSL

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.
 
G

GSL

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.
 
A

afshar

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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top