Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

how we can hide and show some specific div contents using javascript and asp.net please share a tutorial plzzz
Posted
Updated 13-Jan-17 0:14am

JavaScript

Call below function and pass the Control ID to hide/show it alternatively.
JavaScript
function toggleVisibility(controlId)
{
    var control = document.getElementById(controlId);

    if(control.style.visibility == "visible" || control.style.visibility == "")
        control.style.visibility = "hidden";
    else
        control.style.visibility = "visible";

}
 
Share this answer
 
Comments
Member 12772705 27-Dec-16 6:00am    
This code work fine but when my page is post back it will not work all div get hidden
Then check your code not to post back.
At first I thought you're talking about Show/Hide elements but realized the thing after couple of seconds. Here you go.
Dynamically shortened Text with “Show More” link using jQuery[^]

If I'm wrong then check this
Show/hide elements dynamically in web page[^]
 
Share this answer
 
See the following code
XML
<html>
<h2>Hide Div in JavaScript</h2>
<script language=javascript type='text/javascript'>
function hideDiv() {
if (document.getElementById) {
document.getElementById('div').style.visibility = 'hidden';
}
}
function showDiv() {
if (document.getElementById) {
document.getElementById('div').style.visibility = 'visible';
}
}
</script>
<body onload="javascript:showDiv()">
<button onclick="javascript:hideDiv()">Hide</button>
<button onclick="javascript:showDiv()">Show</button>
<div id="div">Hello World</div>
</body>
</html>
 
Share this answer
 
XML
<html>
<h2>Hide Div in JavaScript</h2>
<script language="javascript" type='text/javascript'>
function hideDiv() {
if (document.getElementById) {
document.getElementById('div').style.display= 'none';
}
}
function showDiv() {
if (document.getElementById) {
document.getElementById('div').style.display= 'block';
}
}
</script>
<body onload="javascript:showDiv()">
<button onclick="javascript:hideDiv()">Hide</button>
<button onclick="javascript:showDiv()">Show</button>
<div id="div">Hello World</div>
</body>
</html>
 
Share this answer
 
v2
Comments
irfanniazi 13-Nov-13 9:14am    
Thanks a lot
!!
If you want to do it in server side.Simply make the div as server side by adding runat attribute and you can able to control the functionality of the div
 
Share this answer
 
Hi, For this you can use jquery show() hide() . check the below link

http://www.dotnetpools.com/2013/06/code-to-hide-show-div-using-jquery.html[^]
 
Share this answer
 
Comments
Member 12772705 27-Dec-16 5:59am    
it is not working when page is postback help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900