简体   繁体   中英

ASP.NET button not running code behind

I am working with ASP.NET. I have a couple of pages and several ASP.NET Buttons within them. Everything was working fine the other day and now the ASP Buttons are not running the code behind. I have placed Break points in the code so this is how I know they are not running. I have looked around the internet and tried a few things I have found, like cleaning the solution, clearing cache and cookies. I have even added a new button and that won't run the code behind either. It seems to just be the one page that is having the problem with all the buttons on it. Does anyone have any suggestions as to what this may be and how to fix it?

These are the buttons

   <asp:button id="b1" runat="server" OnClick="b1_Click1" Text="Goals" OnClientClick="changegoals(); return false;" CssClass="button"></asp:button>
        <asp:button id="b2" runat="server" OnClick="b2_Click"  Text="Habits" OnClientClick="changehabits(); return false;" CssClass="button"></asp:button>
        <asp:button id="b3" runat="server" OnClick="b3_Click" Text="Diary" OnClientClick="changediary(); return false" CssClass="button"></asp:button>

Why you return false on client click

<asp:button id="b1" runat="server" OnClick="b1_Click1" Text="Goals"     OnClientClick="changegoals(); return false;" CssClass="button"></asp:button>
<asp:button id="b2" runat="server" OnClick="b2_Click"  Text="Habits" OnClientClick="changehabits(); return false;" CssClass="button"></asp:button>
<asp:button id="b3" runat="server" OnClick="b3_Click" Text="Diary" OnClientClick="changediary(); return false" CssClass="button"></asp:button>

You have to return true on client click.

<asp:button id="b3" runat="server" OnClick="b3_Click" Text="Diary" OnClientClick="changediary(); return true" CssClass="button"></asp:button>

Verify if the button has the following code:

I had a similar issue and I resolved it by adding OnClick="Button_Click" keyword

Hope this helps!

I have always programmed in VB and have just recently been writing in C#. Have already come across this irritating behaviour. Adding the OnClick="whatevercode" in the mark-up seems to fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM