Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net Button OnClick event not firing

Tags:

c#

asp.net

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) {  } 
like image 715
Amjad Shah Avatar asked Mar 22 '13 12:03

Amjad Shah


People also ask

How to make OnClick event in asp net?

From the controls toolbar drag a button over to the page. If you double click the button in design view it will automatically create the event handler in code behind. The button control has a couple of properties OnClick and OnClientClick. Use OnClientClick to trigger any JavaScript on the page.

Which event is raised when the button control is clicked?

The Click event is raised when the Button control is clicked. This event is commonly used when no command name is associated with the Button control (for instance, with a Submit button). For more information about handling events, see Handling and Raising Events.


2 Answers

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"/>  
like image 64
Chani Poz Avatar answered Sep 19 '22 01:09

Chani Poz


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

like image 40
Lingaraj Avatar answered Sep 21 '22 01:09

Lingaraj