[c#] asp.net Button OnClick event not firing

I have problem in asp.net button control.

I define a button in form, onclick event of button is not firing when I click on the button.

<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" /> 

protected void btn_QuaSave_Click(object sender, EventArgs e)
{

}

This question is related to c# asp.net

The answer is


Try to go into Design mode in Visual Studio, locate the button and double click the button that should setup the event. Otherwise once the button is selected in Design more, go to the properties and try setting it from there.


If you are using updatepanel on onclick event, this may happen.

Use 'EnableEventValidation="false"' in your page markup like this :

<%@ Page Language="C#" MasterPageFile="~/ars_home.master" AutoEventWireup="true" CodeFile="Transaction_Window.aspx.cs" Inherits="Transaction_Window" EnableEventValidation="false" %>

Hope this helps


Because your button is in control it could be that there is a validation from another control that don't allow the button to submit. The result in my case was to add CausesValidation property to the button:

<asp:Button ID="btn_QuaSave" runat="server" Text="SAVE" OnClick="btn_QuaSave_Click" CausesValidation="False"/> 

If it's throwing no error but still not firing the click event when you click the submit button, try to add action="YourPage.aspx" to your form.


Even i had two forms one for desktop view and other for mobile view , Removed one formed worked for me . I dint knew asp.page should have only one form.


I had a similar issue and none of the answers worked for me. Maybe someone finds my solution helpful. In case you do not mind submitting on button click, only attaching to click event setting UseSubmitBehavior="false" may be worth trying.


Add validation groups for your validator elements. This allows you distinguish between different groups which to include in validation. Add validation group also to your submit button


I had the same problem, my aspnet button's click was not firing. It turns out that some where on other part of the page has an input with html "required" attribute on.

This might be sound strange, but once I remove the required attribute, the button just works normally.


i had the same problem did all changed the button and all above mentioned methods then I did a simple thing I was using two forms on a single page and form with in the form so I removed one and it worked :)


in my case: make sure not exist any form element in your page other than top main form, this cause events not fired


Try to Clean your solution and then try once again.

It will definitely work. Because every thing in code seems to be ok.

Go through this link for cleaning solution>

http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/e53aab69-75b9-434a-bde3-74ca0865c165/


In the case of nesting the LinkButton within a Repeater you must using something similar to the following:

<asp:LinkButton ID="LinkButton1" runat="server" CommandName="MyUpdate">LinkButton</asp:LinkButton>

 protected void Repeater1_OnItemCommand(object source, RepeaterCommandEventArgs e)
 {
    if (e.CommandName.Equals("MyUpdate"))
    {
        // some code
    }
 }

If the asp button is inside <a href="#"> </a> tag then also the Click event will not raise.

Hope it's useful to some one.


In my case I put required="required" inside CKEditor control.
Removing this attribute fixed the issue.
Before

<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server" required="required"></CKEditor:CKEditorControl>

After

<CKEditor:CKEditorControl ID="txtDescription" BasePath="/ckeditor/" runat="server"></CKEditor:CKEditorControl>