Page_Load not getting called?

A

Adam Clauss

I have a webapp which consists of several different webforms.
Basically:
(1) view the contents of a database
(2) one is to add a new entry
(3) confirms the new entry.

The third form, upon confirming the entry (in a button_clicked handler) adds
the entry into the database and then redirects back to (2) using
Response.Redirect(..)

However, I've recently run into a problem - for some reason the Page_Load in
(2) is not getting called. At all. I noticed it first when I added the
redirect from (3). That redirects and adds a URL parameter
("event.aspx?added=true"). In the Page_Load of (2), I added a conditional
that "if (Request.QueryString["added"] == "true")" then a hidden-by-default
label field gets its Visibility set to true (says "Successfully added").
However, nothing happened - the page loaded as normal, without the new
label.
To test my sanity, I added Response.Redirect("www.yahoo.com", true) as the
very first line in Page_Load (not under any conditional - it should happen
everytime). Did a complete rebuild of the application, cleared IE cache,
and directed it to my page. Still loaded as normal - no redirect to yahoo.

Other events on the page (like the form submit button) work fine - it
correctly validates the data (or shows another hidden label if data was
invalid). Page_Load just seems like it is not triggering at all. Any ideas
on what might be happening?

Thanks!

Adam Clauss
(e-mail address removed)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Check that you have this code:
protected override void OnInit(System.EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{

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

Cheers,
 
M

Martin Dechev

Hi,

How is your Page_Load declared, does it match the EventHandler signature and
what accessible level does it have?

If AutoEventWireUp is set to true or missing in the <%@ Page %> directive
the accessible level of the auto-wired-up handlers should be public or
protected. If these are private or internal they will not be attached to the
event(s).

If AutoEventWireUp is false - check in the designer-generated code
(InitializeComponent) if Page_Load is attached to the Load event. In this
case the accessible level doesn't matter.

Also, there are some reports for server caching of the aspx pages,
especially on IIS6 (Windows 2003). To rule out this add the following code
to your Application_BeginRequest handler in the global.asax of the
application:

Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.AppendHeader("Pragma", "no-cache");

compile, restart the www service and run the webapp.

Hope this helps
Martin Dechev
ASP.NET MVP
 
G

Guest

Adam,

Also check that your page directive correctly shows the Inherits attribute
for your code behind library, eg:
<%@ Page language="c#" Inherits="WebApplication1.WebForm1" %>

If your other events are firing OK this probably is already OK, but it may
be that the validation you are seeing is only happening on the client side.

Chris.


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Check that you have this code:
protected override void OnInit(System.EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{

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

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Adam Clauss said:
I have a webapp which consists of several different webforms.
Basically:
(1) view the contents of a database
(2) one is to add a new entry
(3) confirms the new entry.

The third form, upon confirming the entry (in a button_clicked handler) adds
the entry into the database and then redirects back to (2) using
Response.Redirect(..)

However, I've recently run into a problem - for some reason the Page_Load in
(2) is not getting called. At all. I noticed it first when I added the
redirect from (3). That redirects and adds a URL parameter
("event.aspx?added=true"). In the Page_Load of (2), I added a conditional
that "if (Request.QueryString["added"] == "true")" then a hidden-by-default
label field gets its Visibility set to true (says "Successfully added").
However, nothing happened - the page loaded as normal, without the new
label.
To test my sanity, I added Response.Redirect("www.yahoo.com", true) as the
very first line in Page_Load (not under any conditional - it should happen
everytime). Did a complete rebuild of the application, cleared IE cache,
and directed it to my page. Still loaded as normal - no redirect to yahoo.

Other events on the page (like the form submit button) work fine - it
correctly validates the data (or shows another hidden label if data was
invalid). Page_Load just seems like it is not triggering at all. Any ideas
on what might be happening?

Thanks!

Adam Clauss
(e-mail address removed)
 
G

Guest

Turn on your load on "every visit to the page" option in
IE, else don't rely on the page being relaaded when you
are just redirected to it.
 
A

Adam Clauss

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Check that you have this code:
protected override void OnInit(System.EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{

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

Wierd... I hadn't thought to check inside that region (as I hadn't modified any of it - by hand anyway). But yeah, the adding of
the event handler was completely gone... everything else was fine, just that. Visual Studio scares me sometimes :)

Thanks for your help!
 

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

Top