Page_Load event not executing

G

Guest

Hello:

I'm facing a very strange problem.

When I run my Web application in Visual Studio.NET the Page_Load event is not executing. Other events like a Button_Click are executing.

It doesn't matter whether I'm running the application in VS.NET or browsing it using http://localhost/... the Page_Load event is not executing under either conditions.

I've determined that this problem occurs in both VB.NET and VC#.NET. The Page_Load event is not executing.

Can someone please explain how to solve this?

Thanks.
 
K

Ken Cox [Microsoft MVP]

Hi,

The page load event must be happening if you can get to the point where you
can click a button... otherwise there would be no page.

Is it possible that the handler code has been corrupted? An older version of
VS.NET sometimes removed the Handles clause.

Does the code look like this?

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Are you debugging? It is also possible that the debugger may be skipping the
breakpoint.

Can you post the code?

Ken
 
G

Guest

Hi Ken:

Here's the code. Its placed along with the HTML in the same file, not in a code-behind file:

Sub Page_Load(Sender As object, E As EventArgs)

If Not Page.IsPostBack Then
state.Items.Add("CA")
state.Items.Add("IN")
state.Items.Add("KS")
state.Items.Add("MD")
state.Items.Add("MI")
state.Items.Add("OR")
state.Items.Add("TN")
state.Items.Add("UT")
End If

End Sub
 
K

Ken Cox [Microsoft MVP]

I'm not good at C#, but you have to add the event handler differently than
in VB:

this.Load += new System.EventHandler(this.Page_Load);

Here's what the VS.NET designer generates:

namespace p4320workcs
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
 
J

Jim White

Make sure in your .cs page you have the following line in your
InitializeComponent function.

this.Load += new System.EventHandler(this.Page_Load);
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top