Page_Load Not Firing?

R

Rohan Parkes

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
Melbourne
Australia

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

protected void BindGrid()
{
NewsMailer.ListsDB lists = new NewsMailer.ListsDB
(GetConnString());
// get all the lists
DataView myDV = lists.GetLists().Tables
[0].DefaultView;

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

ListsGrid.DataSource = myDV;
ListsGrid.DataBind();
}
 
M

Munsifali Rashid

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,

Mun
 
R

Rohan Parkes

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.

Thanks - that was it. I can only assume that importing the pages messed
something up.
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top