To really understand the Page_Load event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear colleagues,
I kindly ask the C# developers community to help me to REALLY understand
the Page_Load event, so to REALLY have it under control.

Reason for this question is that I cannot anymore accept passively the
behavior of the “Web Form Designer†automatically generated code because of
the fact that, in some circumstances (that I can reproduce at will), my code
is victim of a Page_Load multiple “firingâ€. In other words the Page_Load
event handler inexplicably enters more than once and, at the second entry,
Login credentials are asked again interactively. With disruptive effects for
my current project.

Let me begin this discussion with what I certainly do not know, or I do not
know for sure.


P1) I do not know what really triggers the OnInit event, beyond the fact
that it is overridden in the “Web Form Designer†automatically generated code
(see hereafter).


P2) I do not know what really the original base.OnInit(e) at last will do.
Indeed I’ve found documentation only about Control.OnInit, but I’m not
convinced it can apply to this case, where no server control in involved
(please see next point), and such an article, as the “ASP.NET Server Control
Event Modelâ€, doesn’t exactly apply. Does it?


P3) Consider that, by definition, “events associated with server controls
are raised on the client but handled on the Web server by the ASP.NET page
frameworkâ€. Here the case of OnInit, of an .aspx Web page, is rather
different, isn’t it? Indeed the OnInit event happens BEFORE the presence of
the Web page on the client computer, indeed this is the very event of posting
a page from the server to the client. And this event shouldn’t happen again
until I deliberately ask for another .aspx page. Shouldn’t it? But, alas, it
DOES happen, out of my control. And all that is precisely the reason of this
call “To really understand the Page_Load eventâ€.

As you see I’m really confused (and baffled too…).
Thanks for your time.
P.M.

- - - - -=- - - - -=- - - - -=
“Web Form Designer†automatically generated code:

#region Web Form Designer generated code
override protected void OnInit(aS.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
 
Thanks for your suggestion.

Anyhow, may I?:
Here too this paper is talking about the “phases in the lifecycle of a
control.†But I’m concerned with an .aspx page, not with a control possibly
contained in such a page. And I’m not at all convinced that it is the same
thing, or it is equivalent.

See you.
P.M.
 
The order of events for a control and a page are the same. An aspx
(System.Web.UI.Page) is derived from System.Web.UI.Control.

Ollie
 
Back
Top