Amjad Shah
Amjad Shah

Reputation: 595

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

}

Upvotes: 41

Views: 187897

Answers (17)

Dantevip
Dantevip

Reputation: 33

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

Upvotes: 0

Rachit Chauhan
Rachit Chauhan

Reputation: 121

Try this onserverclick

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

Upvotes: 0

Mohammed Ali Asgar
Mohammed Ali Asgar

Reputation: 47

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.

Upvotes: 0

Colin
Colin

Reputation: 1836

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

Upvotes: 1

Ryfcia
Ryfcia

Reputation: 457

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.

Upvotes: 8

Marselus Chia
Marselus Chia

Reputation: 230

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.

Upvotes: 9

Danny
Danny

Reputation: 11

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.

Upvotes: 1

waqar haider
waqar haider

Reputation: 73

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

Upvotes: 2

Mohsen.Sharify
Mohsen.Sharify

Reputation: 257

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

Upvotes: 1

Chani Poz
Chani Poz

Reputation: 1463

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"/> 

Upvotes: 40

user586399
user586399

Reputation:

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

Upvotes: 1

Ravan
Ravan

Reputation: 79

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

Upvotes: 7

Tuyen Nguyen
Tuyen Nguyen

Reputation: 4479

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>

Upvotes: 3

Selmanist
Selmanist

Reputation: 11

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.

Upvotes: 0

Paritosh
Paritosh

Reputation: 4503

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.

Upvotes: 2

Lingaraj
Lingaraj

Reputation: 452

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

Upvotes: 14

Freelancer
Freelancer

Reputation: 9074

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/

Upvotes: 1

Related Questions