1

I'm using asp.net(C#) under visual studio 2010

I have a panel that is by default set 2 be hidden( visible=false)

I need to create a JavaScript function that would be executed on a button click to make this panel visible if hidden and hidden if visible. and this should be client side, here is the code I have so far

   <script type=text/javascript>

    function func1()
    {
    i need this code please
    }

<asp:Panel ID="ResultsPanel" runat="server">

Some controls

</asp:Panel>

<asp:button id=button1 runat=server onclick=javascript:func1()>Hide/Unhide</asp:button>
1
  • If you set visible=false, the panel will not show up in your DOM, and can not be set visible later. You should have visible=true, and then hide it with CSS (style="display:none"), and then show it with one of the below solutions. Commented Sep 21, 2011 at 9:16

3 Answers 3

4

first you need to use OnClientClick attribute instead of OnClick for your button, and if that button does not run any server side code you can use html button instead of asp:Button

 <input type="button" onclick="func1();" value="Hide/Unhide">

you can use toggle function in jquery to hide/unhide your panel

function func1()
{
   var mypanel = $('#<%=ResultsPanel.ClientID%>');
   mypanel.toggle();
}

DEMO

Sign up to request clarification or add additional context in comments.

Comments

3

Try this:

var Panel = document.getElementById("ResultsPanel");
if (Panel.style.display == "block" || Panel.style.display == "")
{
    Panel.style.display = "none";
}
else
{
    Panel.style.display = "block";
}

Comments

1

If you are using jQuery, you may make use of following jQuery methods,

http://api.jquery.com/toggle/

http://api.jquery.com/hide/

http://api.jquery.com/show/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.