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
laceholder 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
osnav 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
laceholder id="BodyPlaceholder" runat="server" />
<!-- end body -->
</form>
</td>
</tr>
<tr>
<td width="24" height="100%" valign="top"> </td>
<td width="165" height="100%" valign="top"
background="images/comp_1_13.gif">
</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"> </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> </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 & 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> </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">
</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
laceholder) 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!
.
.