Why did my events stop working?

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;
}
 
T

Teemu Keiski

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

AW

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top