Why did my events stop working?

  • Thread starter Thread starter phoenix
  • Start date Start date
P

phoenix

I have a form with a Submit button and a few other HTML controls but I'll
leave them out of this for simplicity. When Submit is clicked, the server
looks in the event handler declaration code for the matching event. It
doesn't find it even though it's there and moves on to Page_Load. The
button declaration and event handler code was generated by the IDE. I even
tried re-adding the button and then tried creating a brand new button with a
different ID and adding that to the form instead. Neither tactics worked.

I *know* it's not hitting the event. I have breakpoints all over in my
code. It looks in InitializeComponent and then goes directly to Page_Load.

The SubmitButton:
protected System.Web.UI.WebControls.Button SubmitButton;

EventHandler List:
private void InitializeComponent()
{
this.SubmitButton.Click += new
System.EventHandler(this.SubmitButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}

My SubmitButton_Click handler code:

private void SubmitButton_Click(object sender, System.EventArgs e)
{
int i = 0;
}
 
Hi,

you did understand that these postback events are raised *after* Page_Load?
You just said:
"the server
looks in the event handler declaration code for the matching event. It
doesn't find it even though it's there and moves on to Page_Load", so I
thought I'd make it sure.
 
Ok, the breakpoints aren't reached, but is the code executed anyway? I mean,
is the code in the Page_Load executed? To be sure about that, you can place
a Response.Write in it.
If the breakpoint isn't reached AND the code isn't executed, it is most
likely that your Page_Load is not called. This may be due to a bug in Visual
Studio.net, where it removes the event handlers:
-if using VB.Net, check that the "Handles Page.Load" wasn't removed at the
end of the Page_Load declaration
-if using C#, check that the Page.Load += new EventHandler(Page_Load) is
still there in the hidden code part of the CodeBehind file.
 
Back
Top