3
votes

I have a ASP.NET web form. The first time I submit the form, the SubmitButton_Click event is raised.

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

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

Does anyone know why I would be seeing this behavior on the server side?

(I am using jQuery and the validation control client-side but I don't think it is causing an issue. Thought I would mention it anyway).

Edit:

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

Event is set on the control, not in code.

4
Code will help. Especially how you are wiring up your event handler. - Aaron Daniels

4 Answers

2
votes

This can happen with dynamically created controls, if you don't create them early enough in the page life cycle. You're a bit short on details, but is your button created dynamically?

0
votes

Is the JQuery submitting the form? If __doPostBack() isn't called on the client side (with the approprate arguements), the server side event won't occure.

0
votes

How are you "wiring up" your event handler?

It sounds like you are wiring it up in a if(IsPostback) block, which is not being run the second time...

0
votes

How is the Click event handler associated with the submit button? Declaratively or in code?

If it's in code, make sure that you're not doing it in a block like this:

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

This will prevent the event handler from being attached when the page is posted back (i.e. Page.IsPostBack is true).