Page_Load event not executing

Discussion in 'ASP .Net' started by Guest, Jul 13, 2004.

  1. Guest

    Guest 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.
     
    Guest, Jul 13, 2004
    #1
    1. Advertisements

  2. 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
     
    Ken Cox [Microsoft MVP], Jul 13, 2004
    #2
    1. Advertisements

  3. Guest

    Guest 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
     
    Guest, Jul 13, 2004
    #3
  4. Guest

    Guest Guest

    Hi Ken:

    It now works. I added the "Handles" clause and now it works.

    Thanks.
     
    Guest, Jul 13, 2004
    #4
  5. Guest

    Guest Guest

    Hi Ken:

    What's the syntax for the Handles clause in C#?

    Thanks.
     
    Guest, Jul 13, 2004
    #5
  6. Ken Cox [Microsoft MVP], Jul 13, 2004
    #6
  7. 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
    }
    }
     
    Ken Cox [Microsoft MVP], Jul 13, 2004
    #7
  8. Guest

    Jim White Guest

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

    this.Load += new System.EventHandler(this.Page_Load);
     
    Jim White, Jul 13, 2004
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.