470,641 Members | 2,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

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

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.
Apr 24 '06 #1
6 2048
GSL
Unless I misunderstood the question, the following js should work:

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

"Nestor" <n3****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.

Apr 24 '06 #2
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?
"GSL" <Gu***********@gmail.com> wrote in message
news:Eo******************************@comcast.com. ..
Unless I misunderstood the question, the following js should work:

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

"Nestor" <n3****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.


Apr 25 '06 #3
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.

"Nestor" <n3****@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP02.phx.gbl...
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?
"GSL" <Gu***********@gmail.com> wrote in message
news:Eo******************************@comcast.com. ..
Unless I misunderstood the question, the following js should work:

document.getElementById( {ID of ASP.net control} ).style.display = 'none'.
"Nestor" <n3****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.



Apr 25 '06 #4
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.

"Nestor" <n3****@yahoo.com> wrote in message
news:O9**************@TK2MSFTNGP02.phx.gbl...
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?
"GSL" <Gu***********@gmail.com> wrote in message
news:Eo******************************@comcast.com. ..
Unless I misunderstood the question, the following js should work:

document.getElementById( {ID of ASP.net control} ).style.display = 'none'.
"Nestor" <n3****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.



Apr 25 '06 #5
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

Apr 25 '06 #6
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.

"Nestor" <n3****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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.

Apr 25 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by James | last post: by
1 post views Thread by Brenton | last post: by
5 posts views Thread by Peter Afonin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.