Visibility of servercontrols thrue javascript

D

Dahab

Hi,
Anyone know if it's possible to set the visibilty of a servercontrol thru
javascript.
Think it would go something like this, but its not working:

document.forms[0]['TextBox1'].style.visibility == 'hidden'

Thanks
T.
 
M

Marina Levit [MVP]

There is no way to do this.

You can control whether the control is visible in the browser. But this has
nothing to do with the Visible property on the server. In fact, if Visible
is False on the server, the HTML for that control won't even be streamed
down to the client.
 
D

Dahab

Hi Marina,
I'm only trying to hide the servercontrol on the client.
Thanks

T.

Marina Levit said:
There is no way to do this.

You can control whether the control is visible in the browser. But this
has nothing to do with the Visible property on the server. In fact, if
Visible is False on the server, the HTML for that control won't even be
streamed down to the client.

Dahab said:
Hi,
Anyone know if it's possible to set the visibilty of a servercontrol thru
javascript.
Think it would go something like this, but its not working:

document.forms[0]['TextBox1'].style.visibility == 'hidden'

Thanks
T.
 
D

Dahab

Jippi its working!
Thanks..

Marina Levit said:
There is no way to do this.

You can control whether the control is visible in the browser. But this
has nothing to do with the Visible property on the server. In fact, if
Visible is False on the server, the HTML for that control won't even be
streamed down to the client.

Dahab said:
Hi,
Anyone know if it's possible to set the visibilty of a servercontrol thru
javascript.
Think it would go something like this, but its not working:

document.forms[0]['TextBox1'].style.visibility == 'hidden'

Thanks
T.
 
L

Laurent Bugnion

Hi,
Not working even without me typo !
Sorry !

Hi,
Anyone know if it's possible to set the visibilty of a servercontrol thru
javascript.
Think it would go something like this, but its not working:

document.forms[0]['TextBox1'].style.visibility == 'hidden'

Thanks
T.

JavaScript can only control a CSS style attribute if it is set in the
first place. In your case, you must get the server-side control to add a
"style" attribute with the value "visibility: visible;". This is usually
done using the control's Attributes collection.

Note that for this kind of effects, you probably rather want to use
display: "display: block;".

After that, JavaScript can access the element, and modify the style
attribute:

if ( document.getElementById( "TextBox1" )
&& document.getElementById( "TextBox1" ).style
&& document.getElementById( "TextBox1" ).style.display )
{
document.getElementById( "TextBox1" ).style.display = "none";
}

HTH,
Laurent
 
D

Dahab

Hi Laurent,
This is very good information
Thanks
T.
Laurent Bugnion said:
Hi,
Not working even without me typo !
Sorry !

Hi,
Anyone know if it's possible to set the visibilty of a servercontrol thru
javascript.
Think it would go something like this, but its not working:

document.forms[0]['TextBox1'].style.visibility == 'hidden'

Thanks
T.

JavaScript can only control a CSS style attribute if it is set in the
first place. In your case, you must get the server-side control to add a
"style" attribute with the value "visibility: visible;". This is usually
done using the control's Attributes collection.

Note that for this kind of effects, you probably rather want to use
display: "display: block;".

After that, JavaScript can access the element, and modify the style
attribute:

if ( document.getElementById( "TextBox1" )
&& document.getElementById( "TextBox1" ).style
&& document.getElementById( "TextBox1" ).style.display )
{
document.getElementById( "TextBox1" ).style.display = "none";
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top