private void Page_Load Fires Three Times

  • Thread starter Thread starter Luke Ward
  • Start date Start date
L

Luke Ward

When users try to goto my page (default.aspx) it checks for a certain
session var being set to a certain value, if it is it loads page other wise
it bounces to login page.

Problem is after the user has logged in the page_load event fires three
times and I have no idea why? This causes me more of an issue because I
have inserted javascript that warns user the page is closing (3 times)......

var fCanClose = false;
function checkUnload()
{
if (!fCanClose) window.event.returnValue = "Any changes made to this
page will be lost.";
}
window.onbeforeunload = checkUnload;

Cheers

Luke
 
Hi Luke,

Could you provide some more code as what you have given doesn't really
give us much information.
 
Yeah sorry - that was just the js to stop the window closing, I know that's
not what causes the event to reoccur.....My app uses .....<authentication
mode="Forms">
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();

this.sqlConnection1.ConnectionString =
ConfigurationSettings.AppSettings["ConnectionString"];

this.sqlCommand1.CommandText = "dbo.[up_Select_MyTable]";

this.sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure;

this.sqlCommand1.Connection = this.sqlConnection1;

this.sqlCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@lngPrimary", System.Data.SqlDbType.Int,
4));

this.sqlCommand1.Parameters["@lngPrimary"].Value = intRecord;


SqlDataAdapter da = new SqlDataAdapter(this.sqlCommand1);

DataSet ds = new DataSet();

da.Fill(ds);

for(int i=0;i<ds.Tables[8].Rows.Count;i++)

{

DataRow dataRow = ds.Tables[8].Rows;

Question ctlBody = (Question)Page.LoadControl("question.ascx");

Question ctlChassis = (Question)Page.LoadControl("question.ascx");


//Chassis

ctlChassis.sQuestion = "What chassis makes do you run at " +
dataRow["F1"].ToString() + " kg?";

ctlChassis.Data = "dbo.up_Select_tblChassis";

ctlChassis.OptionsSP = "dbo.up_Select_tblManufacturer_Weight_Ranges " +
dataRow["IDX"];

ctlChassis.UpdateProcName = "dbo.up_Insert_tblChassis";

ctlChassis.ID = "chassis" + dataRow["idx"].ToString();

ctlChassis.Weight = int.Parse(dataRow["idx"].ToString());

ctlChassis.Record = intRecord;

//Bodies

ctlBody.sQuestion = "What body types do you run at " +
dataRow["F1"].ToString() + " kg ?";

ctlBody.Data = "dbo.up_Select_tblBody";

ctlBody.OptionsSP = "dbo.up_Select_tbl_LB_Bodies";

ctlBody.UpdateProcName = "dbo.up_Insert_tblBody";

ctlBody.ID = "body" + dataRow["idx"].ToString();

ctlBody.Weight = int.Parse(dataRow["idx"].ToString());

ctlBody.Record = intRecord;

//Hide all but first weight question

if(i>0)

{

ctlChassis.Visible = false;

ctlBody.Visible = false;

}

tdBC.Controls.Add(ctlBody);

tdBC.Controls.Add(ctlChassis);

}
 
Sorted, the following Javascript caused my problems

function forceReload() {
if (document.images)
location.replace(location.href + '?' + (new Date()).getTime());
else
location.href = location.href + '?' + (new Date()).getTime();
}

var lastTime = location.search.substring(1) - 0;

alert(lastTime + "---" + new Date().getTime());

if ((new Date()).getTime() - lastTime > 1000)
forceReload();

Cheers

Luke

--
Campbells Commercial Vehicle Marketing Group
The Old Police Station
Golden Hill
Leyland
PR25 3NN

Tel: +44 (0)1772 433303
Fax: +44 (0)1772 433772
e-mail: (e-mail address removed)
Website: www.campbelluk.com
Follow this link to find us on a map...
http://www.streetmap.co.uk/streetmap.dll?P2M?P=pr253nn&Z=1



****************************************************************************
*******************************************************************
Disclaimer
This message is confidential to the recipient(s) in person. It may be
legally privileged. It is intended only for the stated addressee(s) and
access to it by any other person is unauthorised. If you are not the
addressee, you must not disclose, copy, circulate or in any other way use or
rely on the information contained in this correspondence.

The contents do not constitute a commitment by Campbells except where
expressly provided for in written agreement between you and Campbells. Any
unauthorised disclosure, use or dissemination, either whole or partial is
prohibited. Campbells takes no responsibility for the accuracy of the data
contained in this correspondence.

If you receive this correspondence in error, please inform Campbells on +44
(0)1772 433303 and delete all copies from your system.
Luke Ward said:
Yeah sorry - that was just the js to stop the window closing, I know that's
not what causes the event to reoccur.....My app uses .....<authentication
mode="Forms">
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();

this.sqlConnection1.ConnectionString =
ConfigurationSettings.AppSettings["ConnectionString"];

this.sqlCommand1.CommandText = "dbo.[up_Select_MyTable]";

this.sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure;

this.sqlCommand1.Connection = this.sqlConnection1;

this.sqlCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@lngPrimary", System.Data.SqlDbType.Int,
4));

this.sqlCommand1.Parameters["@lngPrimary"].Value = intRecord;


SqlDataAdapter da = new SqlDataAdapter(this.sqlCommand1);

DataSet ds = new DataSet();

da.Fill(ds);

for(int i=0;i<ds.Tables[8].Rows.Count;i++)

{

DataRow dataRow = ds.Tables[8].Rows;

Question ctlBody = (Question)Page.LoadControl("question.ascx");

Question ctlChassis = (Question)Page.LoadControl("question.ascx");


//Chassis

ctlChassis.sQuestion = "What chassis makes do you run at " +
dataRow["F1"].ToString() + " kg?";

ctlChassis.Data = "dbo.up_Select_tblChassis";

ctlChassis.OptionsSP = "dbo.up_Select_tblManufacturer_Weight_Ranges " +
dataRow["IDX"];

ctlChassis.UpdateProcName = "dbo.up_Insert_tblChassis";

ctlChassis.ID = "chassis" + dataRow["idx"].ToString();

ctlChassis.Weight = int.Parse(dataRow["idx"].ToString());

ctlChassis.Record = intRecord;

//Bodies

ctlBody.sQuestion = "What body types do you run at " +
dataRow["F1"].ToString() + " kg ?";

ctlBody.Data = "dbo.up_Select_tblBody";

ctlBody.OptionsSP = "dbo.up_Select_tbl_LB_Bodies";

ctlBody.UpdateProcName = "dbo.up_Insert_tblBody";

ctlBody.ID = "body" + dataRow["idx"].ToString();

ctlBody.Weight = int.Parse(dataRow["idx"].ToString());

ctlBody.Record = intRecord;

//Hide all but first weight question

if(i>0)

{

ctlChassis.Visible = false;

ctlBody.Visible = false;

}

tdBC.Controls.Add(ctlBody);

tdBC.Controls.Add(ctlChassis);

}
 
Back
Top