views:

1909

answers:

4

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.

A: 

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

nikmd23
Beat me to it! I think you mean if (!IsPostBack) though :-)
dariom
No, not wired in code behind.
y0mbo
A: 

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.

jrcs3
The form is still posting to the server as Page_Load fires. That's what seems strange to me.
y0mbo
Page_Load() is fired whenever the page is loaded for any reason, so that doesn't rule out my suggestion. If you can rule out my suggestion, @Joel Coehoorn and @nikmd23 also have important things to look at.
jrcs3
I guess this is probably what is happening. The validation routine seems to submit the form before the __doPostBack() can be called.
y0mbo
A: 

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

dariom
+1  A: 

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?

Joel Coehoorn