Show/Hide elements in ASP.Net without postback.

Is there anyway to show/hide elements on a web form without doing a postback?  Thanks!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

To hide :
document.getElementById("<%= TextBox1.ClientID %>").style.display = "none";
To show :
document.getElementById("<%= TextBox1.ClientID %>").style.display = "none";

Be sure to use CSS to hide your element and not the Visible propertie
So instead :
<asp:Textbox ID="TextBox1" Visible="False"
use :
<asp:Textbox ID="TextBox1" Style="display:none;"
Hans LangerCommented:
ASP.NET is compiled and executed in the server side, that why it need to do post back (Sync or Async).
If you want to hide an HTML element without using, then you can use the <script> tags in your HTML code to add a javascript code that will be executed when the client receive the page:
window.onload = function(){ // this function will be executed after all the elements of the pages are loaded and ready.
    //ADD here to hide the elements
   document.getElementById('fieldtohide').style.display = "none";
   document.getElementById('fieldtoshow').style.display = "visible";

function toggleElementVisibility(element){ = ( = 'none') ? 'visible' : 'none'


Open in new window

you can use "toggleElementVisibility" function to toggle visible/hide an element.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
To show:
document.getElementById("<%= TextBox1.ClientID %>").style.display = "block";

This is probably a case of copy and paste.
Hans LangerCommented:
You are right. it's .style ='block" instead of .style='visible', i don't know what I was thinking on :P
Tapan PattanaikSenior EngineerCommented:
Hi EDW_Gideon,

This is one of the example to  hide /show divs in

<html xmlns="">
<head runat="server">
    <script 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';
    <form id="form1" runat="server">
                <asp:Button id="btnHide" runat="server" Text="Hide" ClientIDMode="Static" OnClientClick="javascript:hideDiv(); return false;"></asp:Button>
                <asp:Button id="btnShow" runat="server" Text="Show" ClientIDMode="Static" OnClientClick="javascript:showDiv(); return false;"></asp:Button>
                <div id="div">show/hide elements on a web form without doing a postback</div>

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.