Results 1 to 6 of 6

Thread: [resolved] show / hide panel

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    [resolved] show / hide panel

    Guys,

    Simple one...

    I want to show or hide a panel when I click on a label on my aspx page. Does anybody have the javascript to do this? I know its simple but its been a while...

    Thanks
    Bob
    Last edited by staticbob; Jan 19th, 2009 at 05:06 AM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: show / hide panel

    How about

    $get('panelID').style.display='none' // for hide

    $get('panelID').style.display='block' // for show

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: show / hide panel

    Try this:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function toggleVisible(){
        var x=document.getElementById('MyDiv');
        if (x) x.style.display=(x.style.display=='none')?'block':'none';
    }
    </script>
    
    </head>
    <body>
    <div id='MyDiv' style='background-color:red'>
        <h1>The div I want to hide/show</h1>
    </div>
    <p>Click on the button to show/hide the div</p>
    <input type='button' value='Click Here' onclick='toggleVisible()'></input>
    </body>
    </html>
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: show / hide panel

    Thanks guys.

    I now have this but its not working, what did I miss???


    Bob


    HTML Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    
    
    <script type="text/javascript">
    function toggleVisible(){
        var x=document.getElementById('Panel1');
        if (x) x.style.display=(x.style.display=='none')?'block':'none';
    }
    </script>
    
    
    
    
    <body>
        <form id="form1" runat="server">
        <div>
        
     
    
    <input type='button' value='Click Here' onclick='toggleVisible()'></input>
    
            <br />
            <uc2:ctl_section ID="ctl_section1" runat="server" Visible="True" />
            <br />
            <br />
            <br />
       
        
        </div>
        </form>
    </body>
    </html>
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: show / hide panel

    ]I see a couple things.
    1. The javascript should be inside the head
    2. The item you are trying to toggle the visiblity is Panel1. I don't see that anywhere in your code.

  6. #6

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: show / hide panel

    Thanks for the responses guys, I've now moved to the ajax accordion control, implementing it as a listview hosting my custom controls. Works a treat.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width