简体   繁体   中英

Button OnClick() Event not Firing

I have an asp.net page in which I'm making an addition that requires me to add another button event. In the example below, btnTwo and btnThree fire their OnClick() events and function as they should. Yet when I added btnOne with its associated OnClick() event, it dose not fire the break point I setup for String test. I inspected the page while running the project and noticed that btnTwo and btnThree have an onclick dopostbackwithoptions in the control yet btnOne dose not. Also when clicking btnOne, pageload events do not fire as well. I don't know whats going on with this or what I am doing wrong. Ive also tried doing a clean build on the solution as that was recommended by another online resource but it still dose not function as it should.

Page:

<table style="width: 210px" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td style="padding-right: 50px">
            <asp:Button ID="btnOne" runat="server" CssClass="DefaultButton" Width="120px" OnClick="btnOne_Click" />
        </td>
        <td style="padding-right: 50px">
            <asp:Button ID="btnTwo" runat="server" ValidationGroup="QtyGroup" CssClass="DefaultButton" Width="90px" OnClick="btnTwo_click" />
        </td>
        <td>
            <asp:Button ID="btnThree" runat="server" CssClass="DefaultButton" Width="90px" OnClick="btnThree_click" />
        </td>
    </tr>
</table>

CodeBehind:

protected void btnOne_Click(object sender, EventArgs e)
    {
        string test = "";
    }

I am willing to bet your button event is firing, but your debugging is not firing. I have seen this when binding the solution to iis incorrectly. In your event, add some code to update a label and I bet it works. Check your URL. I have seen when my IIS binding is incorrect the url changes from localhost:someport to a dns name. This may cause your debugging break points not to fire.

Restart VS and then delete the event name from .aspx page and again create a new event . Some times VS has some problems. It has worked for me sometimes.

Try changing the access modifier to public and see if that makes any difference. I've noticed a similar behavior in WPF.

I also noticed that your event handlers for btnTwo and btnThree have lower case click in handling method name. I'm not sure if you typed the code here by hand or copy/pasted it. Check to make sure that the names match.

Have you copied this method from other page/application ? if yes then it will not work, So you need to delete the event and event name assigned to the button then go to design and go to button even properties go to onClick event double click next to it, it will generate event and it automatically assigns event name to the button. this should work

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