Click here to Skip to main content
12,072,640 members (63,010 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
i want to call toggle function of j query on each click of asp.net button

so i used this code

$("[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 21-Dec-12 8:01am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

try this example--(include jquery 1.4.1)

<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>
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100