Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I press the button it flashes the text but the button resets to its original state. I want it to stay on the text when the button is clicked.
I think it has something to do with "runat='server'" in ASP.net
How do I stop postback in jQuery Buttons?

I tried to add "AutoPostBack=false" to Button1 that did not work
JavaScript
<script type="text/javascript" src="C://Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
      $("#<%= Button1.ClientID %>").on("click", function () {
            $("#<%= Panel1.ClientID %>").fadeToggle(200);
        });
    });
</script>

...
ASP.NET
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:Panel ID="Panel1" style="display:none" runat="server">Toggle Display</asp:Panel>
Posted

Change it to html input type

HTML
<inpput type="button" id="button1" value="Button1" />


JavaScript
<script type="text/javascript">
        $(function () {
          $("#button1").on("click", function () {
                $("#<%= Panel1.ClientID %>").fadeToggle(200);
            });
        });
    </script>
 
Share this answer
 
Alternate Solution could be:
JavaScript
$(function () {
    $("#button1").on("click", function () {
        $("#<%= Panel1.ClientID %>").fadeToggle(200);
        return false; // this will not trigger any server side code to execute.
    });
});

You can put
ASP.NET
<asp:button id="Button1" runat="server" text="Button1" xmlns:asp="#unknown" />
as it is.
 
Share this answer
 

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