script to hide a control

B

billsahiker

I have an asp.net page that dynamically generates client-side
javascript. What javascript would hide a control? Specifically, I have
a composite web server control and when the user clicks a button a
postback occurs and the asp code sets the control's visible property
to false, so when the html is sent back, the control is not visible.
Is there a way to do that in javascript and avoid the postback? Second
question: what is a good book or resource that covers such javascript
topics?

bill
 
J

Jeff Johns

I have an asp.net page that dynamically generates client-side
javascript. What javascript would hide a control? Specifically, I have
a composite web server control and when the user clicks a button a
postback occurs and the asp code sets the control's visible property
to false, so when the html is sent back, the control is not visible.
Is there a way to do that in javascript and avoid the postback? Second
question: what is a good book or resource that covers such javascript
topics?

bill

There are a few ways to show/hide things in javascript which typically
involved setting the style attributes of an element.

visibility: hidden || visible
display: none || (block || inline)

Simple example:

HTML
-----------
<div id="test">This is a test</div>
<a href="#" onclick="toggle('test');">Toggle It</a>

JavaScript
-----------
function toggle(obj)
{
obj = document.getElementById(obj);
if (obj) {
obj.style.display = (obj.style.display != 'none') ? 'none' :
'block';
}
}

A good reference: http://developer.mozilla.org/en/docs/JavaScript

Hope that helps a bit.
 

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
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top