Page_Load Not Firing?

Discussion in 'ASP .Net' started by Rohan Parkes, Dec 16, 2003.

  1. Rohan Parkes

    Rohan Parkes Guest

    I'm fairly new to ASP.NET, and am trying out the Online Newsletter
    Manager project in Wrox's Beginning C#. The pages are supposed to bind
    various controls (dropdown lists, datagrids) when the pages load,
    through code in the Page_Load event.

    However, it never works the first time the page loads. As far as I can
    see, the Page_Load event doesn't fire, and if I set a break point, the
    compiler says it won't be hit. It does work, however, when I click any
    of the controls that fire isPostBack.

    I haven't had this problem with other ASP.NET applications. The only
    difference I can see is that all of the pages inherit from a base class
    that just contains some utility functions.

    I've reproduced some of the code below. I've seen similar code in some
    of the ASP.NET examples in the SDK. I'm using the 1.0 framework.

    I'd be grateful for any help.

    Rohan Parkes

    namespace NewsMailer
    public class Lists : NewsMailer.BasePage
    protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
    // bind the page's controls

    protected void BindGrid()
    NewsMailer.ListsDB lists = new NewsMailer.ListsDB
    // get all the lists
    DataView myDV = lists.GetLists().Tables

    // sort the data according to the SortExpression
    if ( ListsGrid.Attributes["SortExpression"] != null
    myDV.Sort = ListsGrid.Attributes

    ListsGrid.DataSource = myDV;
    Rohan Parkes, Dec 16, 2003
    1. Advertisements

  2. In the InitializeComponent function (which resides in the "Web Form Designer
    generated code" region), you should have a line which says:

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

    This line of code should be automatically generated, and tells the framework
    to execute the Page_Load function when the page loads. If this line is
    missing, the Page_Load function won't fire. Adding this line should solve
    your problem.

    Hope this helps,

    Munsifali Rashid, Dec 16, 2003
    1. Advertisements

  3. Rohan Parkes

    Rohan Parkes Guest

    Thanks - that was it. I can only assume that importing the pages messed
    something up.
    Rohan Parkes, Dec 17, 2003
    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.