ASP.NET Click () event does not fire on second postback

I have an ASP.NET web form. The first time I submit the form, the SubmitButton_Click event will be raised.

The form is returned to the browser either with validation errors, or with the ability to submit the form with new values.

When the form is marked again, the SubmitButton_Click event never fires. Page_Load fires, but not a button.

Does anyone know why I will see this server-side behavior?

(I use jQuery and client side validation, but I don’t think this is causing the problem. I think I would mention this).

Edit:

<asp:Button ID="SubmitButton" OnClick="SubmitButton_Click"
      runat="server" />

The event is set on the control, not in the code.

+3
source share
4

JQuery ? __doPostBack() ( ), .

0

, . , ?

+2

"" ?

, if (IsPostback), ...

0

Click ? ?

If it is in code, make sure you do not do it in a block like this:

if (!Page.IsPostBack) {
    submitButton.Click += new EventHandler(submitButton_Click);
}

This will prevent the event handler from attaching when the page is submitted (i.e. Page.IsPostBack- true).

0
source

Source: https://habr.com/ru/post/1709813/


All Articles