41

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)
{

}
7
  • 1
    Does this help? stackoverflow.com/questions/2669448/onclick-not-firing Commented Mar 22, 2013 at 12:05
  • 1
    How do you know the event is not firing? Commented Mar 22, 2013 at 12:07
  • Try putting a breakpoint Commented Mar 22, 2013 at 12:08
  • 10
    check the CausesValidation property of your button. set it to False if its true. Also check your asp.net page code file link is exactly same in which you have put the event. Commented Mar 22, 2013 at 12:10
  • Is the button inside a template control (such as an <asp:Repeater> or <asp:GridView>)? Commented Mar 22, 2013 at 12:17

17 Answers 17

40

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"/> 
Sign up to request clarification or add additional context in comments.

Comments

14

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

2 Comments

i not copy it from other page
I ended up reading your answer and deciding to move the page, create a new one named the same and manually move the markup and code behind. Worked like a charm!
9

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.

2 Comments

so weird. This error made me compose my code all over again. Still the same. Thank you for this tip. Had to commend you sir.
if you can ignore required fields put CausesValidation="false" in your asp:button
9

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.

Comments

7

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

Comments

3

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>

2 Comments

Yup, someone stuck a required in the aspx.
@SixOThree You know, Your comment is actually the answer! Thanks a lot.
2

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.

Comments

2

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 :)

1 Comment

That worked for me. In my case, the template i downloaded had a form element which i removed.
1

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/

Comments

1

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

Comments

1

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

Comments

1

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.

1 Comment

That is the magic! I was trying to invoke a login form from a modal popup using JqueryModal. Pulled it out and boom! It worked. thanks.
1

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
    }
 }

Comments

0

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.

Comments

0

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.

Comments

0

Try this onserverclick

<button id ="DemoButton" runat="server" onserverclick="button_Click">Login</button>

Comments

0

I solved the problem by replacing the onclick event to onserverclick and it worked.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.