ASP.Net Panel JQuery SlideToggle Postback

Posted by Germ on Stack Overflow See other posts from Stack Overflow or by Germ
Published on 2010-04-14T17:30:02Z Indexed on 2010/04/14 17:33 UTC
Read the original article Hit count: 689

Filed under:
|

I have an asp.net panel with a style which hides it and I'm using JQuery to slideToggle the panel using a hyperlink. This works fine. However, if I add a button on the page that causes a postback the panel will default back to hidden. I understand why this is happening but what is the best way to keep the panels visibility state when a postback occurs?

<head runat="server">
    <title></title>

    <script type='text/javascript' src="jquery-1.4.1.min.js">
    </script>

    <style type="text/css">
        .panel
        {
            display: none;
        }
    </style>

    <script type="text/javascript">
        $(function() {
            $("#Link1").click(function(evt) {
                evt.preventDefault();
                $('#panelText').slideToggle('slow');
            });
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:HyperLink ID="Link1" runat="server" NavigateUrl="#">SlideToggle
    </asp:HyperLink><br />
    <asp:Panel ID="panelText" runat="server" CssClass="panel">
        Some text</asp:Panel>
    <asp:Button ID="button1" runat="server" Text="Postback" />
    </form>
</body>
</html>

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#