Jordan Foreman
Jordan Foreman

Reputation: 3888

ASP:Button OnClick event not firing in one specific instance

What I have is a popup defined within a user control, that is opened within a taskbar user control, which is attached to a master page, such that:

MasterPage.TaskBarUC.PopupUC

Within the popup, there are two buttons, one to save what the user is trying to do within a database, and one to cancel. I have some codebehind that does the work when the user clicks either button.

So every page has the taskbar, and they can click a button on the taskbar to access the popup and save the information. It works perfectly. However, there is one specific page within the site that needs to access the same popup from a button located on the page, as well as from the taskbar.

The button works, and it opens the popup, but for some reason, and only in this case, the "Save" button doesn't activate my codebehind. It DOES perform the validation that I have it do though. What is also weird is that the cancel button, which also activates some codebehind, does do what its supposed to.

I tried putting a breakpoint right at the beginning of my "Save" event handler, and it never reaches it. Its as if the button is only validating, and completely ignoring its OnClick event.

.aspx

<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" 
    ValidationGroup="Validation" />

Upvotes: 1

Views: 2894

Answers (2)

muthu
muthu

Reputation: 1

Button.CausesValidation property to false worked for me. I am using required field validator for different button. I think this could stop post back even for all other button click events (serverside).

Upvotes: 0

Akram Shahda
Akram Shahda

Reputation: 14781

I guess what happens is that the validation process has failed, which cancel the handling of the Button.Click event.

To check this possibility try to set the value of the Button.CausesValidation property to false and see if the Button.Click handling is going to continue or not.

Upvotes: 1

Related Questions