Page_Load twice

V

V. Jenks

I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
 
P

Peter Rilling

This happens to me when the page load is defined in both the HTML and in the
code-behind. Sometimes the IDE will do one thing while I do another to bind
that event.
 
K

Kumar Reddi

In the html of your aspx, check to see if you have "AutoEventWireup=False"
or not. If you are using code-behind, you need to have this attribute set to
false
 
V

V. Jenks

It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.
 
K

Ken Dopierala Jr.

Hi,

Are you using an master page type architecture? The kind where you have 1
..aspx page that holds the layout and common features and then a bunch of
..ascx pages that are loaded into a place holder for content? If so you
might have some code in your Globabl.asax file that is causing this to
happen. Just a wild guess, but when I was using that architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

V. Jenks said:
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.

-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.
 
J

Juan T. Llibre

Is the page getting posted back ?
Any Postback will trigger Page_Load again.

Try turning on Trace for the page, and look at the trace
log to see exactly what is making Page_Load fire twice.

You're using C#, so the Page directive will be :

<%@ Page Language="C#" Trace="true" %>
( plus any other directives you have for that page )



Juan T. Llibre
===========
V. Jenks said:
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.
-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.
 
G

Guest

Yes, each "section" of my application consists of a master
page with a bunch of dynamically loaded ascx controls based
on user-interaction and other factors.

There isn't anything exotic in my Global.asax, as far as I
know. The only thing is in the Session_Start event
handler, which loads a simple Hashtable into a session
variable, that's it, that's all!

Now my control event handlers aren't getting fired, it's
acting really strange!

-v
-----Original Message-----
Hi,

Are you using an master page type architecture? The kind where you have 1
..aspx page that holds the layout and common features and then a bunch of
..ascx pages that are loaded into a place holder for content? If so you
might have some code in your Globabl.asax file that is causing this to
happen. Just a wild guess, but when I was using that architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.

-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.


.
 
K

Ken Dopierala Jr.

Hi,

A lot of times those systems use the Application_BeginRequest() subroutine
in the Global.asax to do a Context.RewritePath(). Also you might want to
make sure that your section master pages aren't named the same. For example
they might all be named Default.aspx but in different folders. Other than
that all I can recommend is to watch the tracing of your app as it runs. I
mean if your page_load runs and then ends and then runs again something in
between is happening because the page_load isn't calling itself. The trace
information should at least tell you where your app is going before it comes
back. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Yes, each "section" of my application consists of a master
page with a bunch of dynamically loaded ascx controls based
on user-interaction and other factors.

There isn't anything exotic in my Global.asax, as far as I
know. The only thing is in the Session_Start event
handler, which loads a simple Hashtable into a session
variable, that's it, that's all!

Now my control event handlers aren't getting fired, it's
acting really strange!

-v
-----Original Message-----
Hi,

Are you using an master page type architecture? The kind where you have 1
..aspx page that holds the layout and common features and then a bunch of
..ascx pages that are loaded into a place holder for content? If so you
might have some code in your Globabl.asax file that is causing this to
happen. Just a wild guess, but when I was using that architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.


-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this
code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.


.
 
V

V. Jenks

If it'll help, here's some code from the page/control where
this is happening (from another msg. I posted somewhere else):

Everyone's first reaction to this is "You have
autoeventwireup set to 'true'", I assure you this isn't the
case.

I'm completely stumped and I can't figure out why it's
firing twice!?

The master (aspx) page which contains a User Control (ascx)
- it is loaded dynamically through an asp:placeholder in
the master page.

Here's my master page:

//BEGIN CODE ---------------------------

<%@ Page language="c#" Codebehind="pos.aspx.cs"
AutoEventWireup="false" Inherits="Scientifik.Fusion.pos" %>
<%@ Register Tagprefix="sci" Tagname="posnav"
src="~/global/controls/nav/pos_nav.ascx" %>
<%@ Register Tagprefix="sci" Tagname="mainheader"
src="~/global/controls/header/main_header.ascx" %>
<%@ Register Tagprefix="sci" Tagname="mainfooter"
src="~/global/controls/footer/main_footer.ascx" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Scientifik Solutions</title>
<script language="javascript"
src="global/scripts/rollover.js"></script>
<link rel="stylesheet" type="text/css"
href="global/css/fusion_main.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0" onload="preloadImages();">
<table width="100%" height="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="100%" colspan="3" valign="top">
<sci:mainheader id="MainHeader" runat="server" />
</td>
</tr>
<tr>
<td width="24" height="44" valign="top">
<img src="images/pos_nav_leftgap.gif" width="24" /></td>
<td width="165" height="154" valign="top"
background="images/comp_1_13.gif">
<!-- begin navigation -->
<sci:posnav id="PosNav" runat="server" />
<!-- end navigation -->
</td>
<td width="100%" height="100%" valign="top" rowspan="2">
<form id="MainForm" name="MainForm" method="post"
runat="server">
<!-- begin body -->
<asp:placeholder id="BodyPlaceholder" runat="server" />
<!-- end body -->
</form>
</td>
</tr>
<tr>
<td width="24" height="100%" valign="top">&nbsp;</td>
<td width="165" height="100%" valign="top"
background="images/comp_1_13.gif">
&nbsp;
</td>
</tr>
<tr>
<td width="100%" colspan="3">
<sci:mainfooter id="MainFooter" runat="server" />
</td>
</tr>
</table>
</body>
</html>

//END CODE ---------------------------

Now, here's the control that is being loaded. It works
*fine* other than when I step through the code-behind,
Page_Load is fired twice and it is causing a number of
problems elsewhere in my code, making for a real headache:

//BEGIN CODE ---------------------------

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="terminal.ascx.cs"
Inherits="Scientifik.Fusion.Pos.terminal"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="1%" bgcolor="#f1efe2">&nbsp;</td>
<td width="99%" bgcolor="#f1efe2">
<span class="bodyTitle">
Scientifik Fusion ::. Point-of-Sale - New Contact/Order
</span>
</td>
</tr>
</table>
<br />
<table width="100%" border="0" cellpadding="3" cellspacing="3">
<tr>
<td>&nbsp;</td>
<td class="genTitle" colspan="2">
<table border="0" width="100%" cellpadding="3"
cellspacing="3">
<tr>
<td rowspan="2" width="5%">
<img src="images/cashregister.gif" width="32"
height="32" />
</td>
<td class="genTitle" width="95%">
Process New Order &amp; Contact
</td>
</tr>
<tr>
<td class="genBody" width="95%">
Complete the form below to process an order and add a
new contact.
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="genBody" colspan="2">
<table width="100%" border="0" cellpadding="3"
cellspacing="3">
<tr>
<td>
---- THE CONTENTS
HAVE BEEN OMMITTED FOR BREVITY ----
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">
&nbsp;
</td>
</tr>
</table>

//END CODE ---------------------------

There's nothing exotic about the user control or the page
itself, it should be really straightforward. Not that it
would offer any clues but here's my Page_Load event in the
code-behind:

//BEGIN CODE ---------------------------

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
{
//hide options list
OIProdOptionList.Visible = false;

//bind before post-back
this.BindOrderItems();

//load products and options into sessions
this.LoadAllProductsAndOptions();
}
}

//END CODE ---------------------------

-v

-----Original Message-----
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.

-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.
.
 
K

Ken Dopierala Jr.

The Page_Load that is being fired twice, is it in the .ascx file or in the
master .aspx file? Ken.

V. Jenks said:
If it'll help, here's some code from the page/control where
this is happening (from another msg. I posted somewhere else):

Everyone's first reaction to this is "You have
autoeventwireup set to 'true'", I assure you this isn't the
case.

I'm completely stumped and I can't figure out why it's
firing twice!?

The master (aspx) page which contains a User Control (ascx)
- it is loaded dynamically through an asp:placeholder in
the master page.

Here's my master page:

//BEGIN CODE ---------------------------

<%@ Page language="c#" Codebehind="pos.aspx.cs"
AutoEventWireup="false" Inherits="Scientifik.Fusion.pos" %>
<%@ Register Tagprefix="sci" Tagname="posnav"
src="~/global/controls/nav/pos_nav.ascx" %>
<%@ Register Tagprefix="sci" Tagname="mainheader"
src="~/global/controls/header/main_header.ascx" %>
<%@ Register Tagprefix="sci" Tagname="mainfooter"
src="~/global/controls/footer/main_footer.ascx" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Scientifik Solutions</title>
<script language="javascript"
src="global/scripts/rollover.js"></script>
<link rel="stylesheet" type="text/css"
href="global/css/fusion_main.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0" onload="preloadImages();">
<table width="100%" height="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="100%" colspan="3" valign="top">
<sci:mainheader id="MainHeader" runat="server" />
</td>
</tr>
<tr>
<td width="24" height="44" valign="top">
<img src="images/pos_nav_leftgap.gif" width="24" /></td>
<td width="165" height="154" valign="top"
background="images/comp_1_13.gif">
<!-- begin navigation -->
<sci:posnav id="PosNav" runat="server" />
<!-- end navigation -->
</td>
<td width="100%" height="100%" valign="top" rowspan="2">
<form id="MainForm" name="MainForm" method="post"
runat="server">
<!-- begin body -->
<asp:placeholder id="BodyPlaceholder" runat="server" />
<!-- end body -->
</form>
</td>
</tr>
<tr>
<td width="24" height="100%" valign="top">&nbsp;</td>
<td width="165" height="100%" valign="top"
background="images/comp_1_13.gif">
&nbsp;
</td>
</tr>
<tr>
<td width="100%" colspan="3">
<sci:mainfooter id="MainFooter" runat="server" />
</td>
</tr>
</table>
</body>
</html>

//END CODE ---------------------------

Now, here's the control that is being loaded. It works
*fine* other than when I step through the code-behind,
Page_Load is fired twice and it is causing a number of
problems elsewhere in my code, making for a real headache:

//BEGIN CODE ---------------------------

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="terminal.ascx.cs"
Inherits="Scientifik.Fusion.Pos.terminal"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="1%" bgcolor="#f1efe2">&nbsp;</td>
<td width="99%" bgcolor="#f1efe2">
<span class="bodyTitle">
Scientifik Fusion ::. Point-of-Sale - New Contact/Order
</span>
</td>
</tr>
</table>
<br />
<table width="100%" border="0" cellpadding="3" cellspacing="3">
<tr>
<td>&nbsp;</td>
<td class="genTitle" colspan="2">
<table border="0" width="100%" cellpadding="3"
cellspacing="3">
<tr>
<td rowspan="2" width="5%">
<img src="images/cashregister.gif" width="32"
height="32" />
</td>
<td class="genTitle" width="95%">
Process New Order &amp; Contact
</td>
</tr>
<tr>
<td class="genBody" width="95%">
Complete the form below to process an order and add a
new contact.
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="genBody" colspan="2">
<table width="100%" border="0" cellpadding="3"
cellspacing="3">
<tr>
<td>
---- THE CONTENTS
HAVE BEEN OMMITTED FOR BREVITY ----
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3">
&nbsp;
</td>
</tr>
</table>

//END CODE ---------------------------

There's nothing exotic about the user control or the page
itself, it should be really straightforward. Not that it
would offer any clues but here's my Page_Load event in the
code-behind:

//BEGIN CODE ---------------------------

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
{
//hide options list
OIProdOptionList.Visible = false;

//bind before post-back
this.BindOrderItems();

//load products and options into sessions
this.LoadAllProductsAndOptions();
}
}

//END CODE ---------------------------

-v

-----Original Message-----
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.

-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.
.
 
V

V. Jenks

Actually, I forgot to mention one important detail. Each
of my "master" pages inherits from a custom class I wrote,
which itself derives from System.Web.UI.Page.

So, for example, here's my custom PageBase class:

//CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Scientifik.Fusion
{
/// <summary>
/// Base page class for all main application aspx pages.
/// </summary>
public class PageBase : System.Web.UI.Page
{

public PageBase()
{
}


/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, System.EventArgs e)
{
//I would load the placeholder control here
}
}
}

//END CODE

And here would be the code-behind for a "master page":

//CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Scientifik.Fusion
{
/// <summary>
/// </summary>
public class pos : PageBase
{
public pos()
{
//default constructor would pass string values to base
class (PageBase)
//which tell the page-loader what to load
}

#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
}
}

//END CODE

Lo and behold, when stepping through the code, it's
PageBase that's doing Page_Load twice, not the control, it
completely slipped my mind!

Any ideas?

-v
-----Original Message-----
Hi,

A lot of times those systems use the
Application_BeginRequest() subroutine
in the Global.asax to do a Context.RewritePath(). Also you might want to
make sure that your section master pages aren't named the same. For example
they might all be named Default.aspx but in different folders. Other than
that all I can recommend is to watch the tracing of your app as it runs. I
mean if your page_load runs and then ends and then runs again something in
between is happening because the page_load isn't calling itself. The trace
information should at least tell you where your app is going before it comes
back. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Yes, each "section" of my application consists of a master
page with a bunch of dynamically loaded ascx controls based
on user-interaction and other factors.

There isn't anything exotic in my Global.asax, as far as I
know. The only thing is in the Session_Start event
handler, which loads a simple Hashtable into a session
variable, that's it, that's all!

Now my control event handlers aren't getting fired, it's
acting really strange!

-v
-----Original Message-----
Hi,

Are you using an master page type architecture? The kind where you have 1
..aspx page that holds the layout and common features and then a bunch of
..ascx pages that are loaded into a place holder for content? If so you
might have some code in your Globabl.asax file that is causing this to
happen. Just a wild guess, but when I was using that architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.


-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this
code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.



.


.
 
V

V. Jenks

Yeah I tried this, it is not being posted. It's loading
w/o any type of post happening but still doing it twice.
-----Original Message-----
Is the page getting posted back ?
Any Postback will trigger Page_Load again.

Try turning on Trace for the page, and look at the trace
log to see exactly what is making Page_Load fire twice.

You're using C#, so the Page directive will be :

<%@ Page Language="C#" Trace="true" %>
( plus any other directives you have for that page )



Juan T. Llibre
===========
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.
-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.


.
 
J

Juan T. Llibre

At
http://www.mcse.ms/archive109-2003-12-207567.html

Colin reports that removing this line :

this.Load += new System.EventHandler(this.PageLoadEvent);
fixed the same problem you're having.

Rick Strahl [MVP] turned him on to this reasoning :

---000---
Check the setting of AutoEventHookup on the page. If you're
using CodeBehind pages you generally don't want this as the
CodeBehind page automatically generates the OnLoad() event hookup.

Also if your form is inherited and your event hookups in the
base class (in InitializeComponent) you will end up hooking
the eventhandler multiple times and so it fires more than once.

The solution there is to remove the OnLoad code
manually in the implementation level of the form.
---000---

Let us know if this works.

Good luck!



Juan T. Llibre
===========
V. Jenks said:
Actually, I forgot to mention one important detail. Each
of my "master" pages inherits from a custom class I wrote,
which itself derives from System.Web.UI.Page.

So, for example, here's my custom PageBase class:

//CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Scientifik.Fusion
{
/// <summary>
/// Base page class for all main application aspx pages.
/// </summary>
public class PageBase : System.Web.UI.Page
{

public PageBase()
{
}


/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, System.EventArgs e)
{
//I would load the placeholder control here
}
}
}

//END CODE

And here would be the code-behind for a "master page":

//CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Scientifik.Fusion
{
/// <summary>
/// </summary>
public class pos : PageBase
{
public pos()
{
//default constructor would pass string values to base
class (PageBase)
//which tell the page-loader what to load
}

#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
}
}

//END CODE

Lo and behold, when stepping through the code, it's
PageBase that's doing Page_Load twice, not the control, it
completely slipped my mind!

Any ideas?

-v
-----Original Message-----
Hi,

A lot of times those systems use the
Application_BeginRequest() subroutine
in the Global.asax to do a Context.RewritePath(). Also you might want to
make sure that your section master pages aren't named the same. For example
they might all be named Default.aspx but in different folders. Other than
that all I can recommend is to watch the tracing of your app as it runs. I
mean if your page_load runs and then ends and then runs again something in
between is happening because the page_load isn't calling itself. The trace
information should at least tell you where your app is going before it comes
back. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Yes, each "section" of my application consists of a master
page with a bunch of dynamically loaded ascx controls based
on user-interaction and other factors.

There isn't anything exotic in my Global.asax, as far as I
know. The only thing is in the Session_Start event
handler, which loads a simple Hashtable into a session
variable, that's it, that's all!

Now my control event handlers aren't getting fired, it's
acting really strange!

-v

-----Original Message-----
Hi,

Are you using an master page type architecture? The kind
where you have 1
..aspx page that holds the layout and common features and
then a bunch of
..ascx pages that are loaded into a place holder for
content? If so you
might have some code in your Globabl.asax file that is
causing this to
happen. Just a wild guess, but when I was using that
architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

message
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.


-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this
code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.



.


.
 
V

V. Jenks

I've been watching tracing and suprisingly, nothing looks
out of place at all.

The expected events are happening (Init, PreRender,
SaveViewState, Render).

Each of the page controls being loaded are exactly as
expected, looks good there.

It's a GET request, so the form hasn't been posted w/o my
knowledge.

???

-----Original Message-----
Hi,

A lot of times those systems use the
Application_BeginRequest() subroutine
in the Global.asax to do a Context.RewritePath(). Also you might want to
make sure that your section master pages aren't named the same. For example
they might all be named Default.aspx but in different folders. Other than
that all I can recommend is to watch the tracing of your app as it runs. I
mean if your page_load runs and then ends and then runs again something in
between is happening because the page_load isn't calling itself. The trace
information should at least tell you where your app is going before it comes
back. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Yes, each "section" of my application consists of a master
page with a bunch of dynamically loaded ascx controls based
on user-interaction and other factors.

There isn't anything exotic in my Global.asax, as far as I
know. The only thing is in the Session_Start event
handler, which loads a simple Hashtable into a session
variable, that's it, that's all!

Now my control event handlers aren't getting fired, it's
acting really strange!

-v
-----Original Message-----
Hi,

Are you using an master page type architecture? The kind where you have 1
..aspx page that holds the layout and common features and then a bunch of
..ascx pages that are loaded into a place holder for content? If so you
might have some code in your Globabl.asax file that is causing this to
happen. Just a wild guess, but when I was using that architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.


-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this
code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.



.


.
 
G

Guest

Nope, that wasn't it, I'm an idiot apparently.

In my PageBase class, in the Page_Load event I was doing a
redirect on a certain condition.

Well, when the page first loads that condition is always
true and forces the redirect, right back to the originating
page...causing the Page_Load in the PageBase class to fire
a second time.

It was recursive and I didn't even realize it so it was
happening right under my nose.

Thanks for all the help and time guys!

-v

-----Original Message-----
At
http://www.mcse.ms/archive109-2003-12-207567.html

Colin reports that removing this line :

this.Load += new System.EventHandler(this.PageLoadEvent);
fixed the same problem you're having.

Rick Strahl [MVP] turned him on to this reasoning :

---000---
Check the setting of AutoEventHookup on the page. If you're
using CodeBehind pages you generally don't want this as the
CodeBehind page automatically generates the OnLoad() event hookup.

Also if your form is inherited and your event hookups in the
base class (in InitializeComponent) you will end up hooking
the eventhandler multiple times and so it fires more than once.

The solution there is to remove the OnLoad code
manually in the implementation level of the form.
---000---

Let us know if this works.

Good luck!



Juan T. Llibre
===========
Actually, I forgot to mention one important detail. Each
of my "master" pages inherits from a custom class I wrote,
which itself derives from System.Web.UI.Page.

So, for example, here's my custom PageBase class:

//CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Scientifik.Fusion
{
/// <summary>
/// Base page class for all main application aspx pages.
/// </summary>
public class PageBase : System.Web.UI.Page
{

public PageBase()
{
}


/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, System.EventArgs e)
{
//I would load the placeholder control here
}
}
}

//END CODE

And here would be the code-behind for a "master page":

//CODE

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Scientifik.Fusion
{
/// <summary>
/// </summary>
public class pos : PageBase
{
public pos()
{
//default constructor would pass string values to base
class (PageBase)
//which tell the page-loader what to load
}

#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
}
}

//END CODE

Lo and behold, when stepping through the code, it's
PageBase that's doing Page_Load twice, not the control, it
completely slipped my mind!

Any ideas?

-v
-----Original Message-----
Hi,

A lot of times those systems use the
Application_BeginRequest() subroutine
in the Global.asax to do a Context.RewritePath(). Also you might want to
make sure that your section master pages aren't named the same. For example
they might all be named Default.aspx but in different folders. Other than
that all I can recommend is to watch the tracing of your app as it runs. I
mean if your page_load runs and then ends and then runs again something in
between is happening because the page_load isn't calling itself. The trace
information should at least tell you where your app is going before it comes
back. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Yes, each "section" of my application consists of a master
page with a bunch of dynamically loaded ascx controls based
on user-interaction and other factors.

There isn't anything exotic in my Global.asax, as far as I
know. The only thing is in the Session_Start event
handler, which loads a simple Hashtable into a session
variable, that's it, that's all!

Now my control event handlers aren't getting fired, it's
acting really strange!

-v

-----Original Message-----
Hi,

Are you using an master page type architecture? The kind
where you have 1
..aspx page that holds the layout and common features and
then a bunch of
..ascx pages that are loaded into a place holder for
content? If so you
might have some code in your Globabl.asax file that is
causing this to
happen. Just a wild guess, but when I was using that
architecture on a
project I had that happen. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

message
It's definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that's not what I'm seeing. The Page_Load in
the user control that I'm stepping through fires twice. It
is not defined twice as I'm stepping through it in the
debugger and I'm watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn't happen.


-----Original Message-----
I'm a little rusty having not touched .NET for 6 months and
I can't remember why Page_Load is happening twice in this
code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there's a good reason for it but I'm not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.



.



.


.
 

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