Visibility of servercontrols thrue javascript

  • Thread starter Thread starter Dahab
  • Start date Start date
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.
 
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.
 
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.
 
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.
 
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
 
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
 
Back
Top