Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to call toggle function of j query on each click of asp.net button

so i used this code

C#
$("[id*=btnAwesome]").live("click", function() {
   $("#can").toggle("slow");
       return false;
   });


but this code disable my asp buttons post back so i cant executecode behind

i want such code which help in both
calling j query on each click and also post back
Posted

1 solution

you used Return False this thing stopping page from postback on button click.
----

try this example--(include jquery 1.4.1)

XML
<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');
                if ($('#panelText').hasClass('panel')) {
                    $('#PanelState').attr('value', 'true');
                } else {
                    $('#PanelState').attr('value', 'false');
                }
             });
        });

        $(document).ready(function() {
            if ($('#PanelState').attr('value') == 'false') {
                $('#panelText').addClass('panel');
            }
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:hiddenfield id="PanelState" runat="server" value="false"  />
    <asp:hyperlink id="Link1" runat="server" navigateurl="#" >SlideToggle
    </asp:hyperlink><br />
    <asp:panel id="panelText" runat="server" >
        Some text</asp:panel>
    <asp:button id="button1" runat="server" text="Postback"  />
    </form>
</body>
</html>
 
Share this answer
 
v2

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