R
Rhys
I have a page which has an IFrame on it. The src of the
IFrame is a page with a datagrid on it. The Datagrid has
bound template columns. The columns of the datagrid pass
the bound data value of each cell within it to my code
behind file which generates the HTML to display the data
in a formatted text box, some of which is editable, some
of which is not. The idea here is that the user can look
at a page with a scrolling 'window'. Move through the
editable HTML textboxes in the datagrid displayed in the
scrolling widow, then save all changes en-mass. This is
achieved, the datagrid having some zero width columns
which hold the original values that were in the editable
text boxes also. Basically, each editable field is
retrieved twice from the database, one is displayed as
editable to the user, one is hidden but holds the original
value.
I can achieve a PostBack event for the src of the IFrame
thru' javascript on either an asp.Net or HTML control.
In the Page Load event of the src of the IFrame, I
retrieve the ID values from the datagrid, iterate through
them, getting the editable and original values from the
datagrid, comparing them and saving records where there is
a difference. However, here I have an od issue.
On some machines, sometimes changes aren't saved. I cannot
replicate this on my dev machine, (win 2000 server) or on
a win 95 machine located close to me. It is frequently but
inconsistently replicable on a number of Win NT machines
some 500 miles away from me and on a win xp pro machine
also that distance away. It cannot be replicated on a Win
2003 server .Net development machine that is that
geographically seperated from me. NB: My dev machine is
acting as the Web Server.
The Page_Load event of the IFrame src is below.
<CODE>
private void Page_Load(object sender,
System.EventArgs e)
{/* Validate authentic users */
try
{
if (Session
["Authd"].ToString() == "true")
{
try
{
if (Session
["Role"].ToString() == "compliance")
{
}
else
{
Server.Transfer("frmLogin.aspx");
}
}
catch
(NullReferenceException)
{
Session
["Authd"] = "false";
Server.Transfer("frmLogin.aspx");
}
}
else if (Session
["Authd"].ToString() == "false")
{
Server.Transfer
("frmLogin.aspx");
}
else
{
Session["Authd"]
= "false";
Server.Transfer
("frmLogin.aspx");
}
}
catch (NullReferenceException)
{
Session["Authd"] = "false";
Server.Transfer
("frmLogin.aspx");
}
if (IsPostBack)
{
string[] ID = Request.Form
["txtID"].ToString().Split (',');
int i = 0;
if (Session
["PositionChange"] != null)
{
Session.Add
("PositionChange",0);
}
string MonthlyPeriod =
Dates.GetCCYYMM(DateTime.Now.ToLocalTime());
string UserName = Session
["UserName"].ToString();
for (i=0;i< ID.Length ;i++)
{
// try
// {
int CPID =
Convert.ToInt32(ID);
double
GasPayment = Convert.ToDouble(Request.Form["txtGasPayment"
+ ID].ToString());
double
TotalGasPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsGas" + ID].ToString());
double
ElectricityPayment = Convert.ToDouble(Request.Form
["txtElectricityPayment" + ID].ToString());
double
TotalElectricityPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsElectricity" + ID].ToString());
double
OtherPayment = Convert.ToDouble(Request.Form
["txtOtherPayment" + ID].ToString());
double
TotalOtherPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsOther" + ID].ToString());
double
Overdue = Convert.ToDouble(Request.Form["txtOutstanding" +
ID].ToString());
double
TotalOverdue = Convert.ToDouble(Request.Form
["txtTotalOutstanding" + ID].ToString());
int
PositionChange = Convert.ToInt32(Session
["PositionChange"].ToString());
if
(GasPayment != TotalGasPayments)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double PaymentAmount = GasPayment-TotalGasPayments;
string strSQL = "proc_UpdateFuelPayments " +
"@CPID = " + CPID + ", " +
"@Commodity = 1, " +
"@TotalAmount = " + GasPayment + ", " +
"@PaymentAmount = " + PaymentAmount + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@AuditUser = '" + UserName + "'";
SqlCommand InsertGasPayment = new SqlCommand
(strSQL, cnSQLLogin);
InsertGasPayment.Connection.Open();
InsertGasPayment.ExecuteNonQuery();
InsertGasPayment.Connection.Close();
}
if
(ElectricityPayment != TotalElectricityPayments)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double PaymentAmount = ElectricityPayment-
TotalElectricityPayments;
string strSQL = "proc_UpdateFuelPayments " +
"@CPID = " + CPID + ", " +
"@Commodity = 2, " +
"@TotalAmount = " + ElectricityPayment + ", " +
"@PaymentAmount = " + PaymentAmount + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@AuditUser = '" + UserName + "'";
SqlCommand InsertElectricityPayment = new
SqlCommand(strSQL, cnSQLLogin);
InsertElectricityPayment.Connection.Open();
InsertElectricityPayment.ExecuteNonQuery();
InsertElectricityPayment.Connection.Close();
}
if
(OtherPayment != TotalOtherPayments)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double PaymentAmount = OtherPayment-
TotalOtherPayments;
string strSQL = "proc_UpdateFuelPayments " +
"@CPID = " + CPID + ", " +
"@Commodity = 3, " +
"@TotalAmount = " + OtherPayment + ", " +
"@PaymentAmount = " + PaymentAmount + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@AuditUser = '" + UserName + "'";
SqlCommand InsertOtherPayment = new SqlCommand
(strSQL, cnSQLLogin);
InsertOtherPayment.Connection.Open();
InsertOtherPayment.ExecuteNonQuery();
InsertOtherPayment.Connection.Close();
}
if
(Overdue != TotalOverdue)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double Difference = Overdue - TotalOverdue;
string strSQL = "proc_UpdateOverdue " +
"@CPID = " + CPID + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@overdue = " + Overdue + ", " +
"@Difference = " + Difference + ", " +
"@AuditUser = '" + UserName + "'";
SqlCommand UpdateOverdue = new SqlCommand(strSQL,
Connection.Connect());
UpdateOverdue.Connection.Open();
UpdateOverdue.ExecuteNonQuery();
UpdateOverdue.Connection.Close();
}
if
(PositionChange < Convert.ToInt32(Session
["PositionChange"].ToString()))
{
string strSQL = "UPDATE tbl_CounterpartyCalcs " +
"SET BalanceDue = COALESCE(((cpc.Overdue +
cpc.DueThisMonth) - cpc.PaymentsMadeReceived),0) " +
"FROM tbl_CounterpartyCalcs cpc " +
"WHERE cpc.CounterpartyId = " + CPID + " " +
"AND cpc.MonthlyPeriod = '" + MonthlyPeriod + "'";
SqlCommand BalanceDue = new SqlCommand(strSQL,
Connection.Connect());
BalanceDue.Connection.Open();
BalanceDue.ExecuteNonQuery();
BalanceDue.Connection.Close();
strSQL = "EXEC sp_Calc_Exposure_CPT " +
"@pFutureYears = 2, " +
"@pCPT = " + CPID + ", " +
"@Result = 0";
SqlCommand UpdateCPPosition = new SqlCommand
(strSQL, cnSQLLogin);
UpdateCPPosition.Connection.Open();
UpdateCPPosition.ExecuteNonQuery();
UpdateCPPosition.Connection.Close();
}
// }
// catch (Exception)
// {
//
Connection.CloseConnection(cnSQLLogin);
// }
}
Session.Add
("PopulateCommodity",0);
}
// Put user code to initialize the
page here
daPayments.SelectCommand.CommandText = "EXEC
proc_Select_PaymentsDue @Commodity = " + Session
["PopulateCommodity"].ToString();
daPayments.SelectCommand.Connection = cnSQLLogin;
daPayments.Fill
(dsNewPayment.tbl_Payment);
Session.Add("PopulateCommodity",0);
// Bind MyDataGrid to the DataSet
DataView s = new DataView
(dsNewPayment.tbl_Payment);
dgPayments.DataSource = s;
dgPayments.DataBind();
}
</CODE>
It validates the user, checks if this is a postback event,
and if it is validdates and saves changes between records,
then reloads the data.
Does anyone have any clues, or is it possible, as I
suspect, that on occassion my error is being caused by the
Top level page with the IFrame on it doing it's postback
first, which I think would simply refresh the data on the
IFrame src as it wouldn't be a PostBack for this page.
This would then postback after the first page and of
course there are no changes to the data as it's just been
reloaded from the database...
....or could this just be an IE bug, or something else
again...
....all help appreciated.
IFrame is a page with a datagrid on it. The Datagrid has
bound template columns. The columns of the datagrid pass
the bound data value of each cell within it to my code
behind file which generates the HTML to display the data
in a formatted text box, some of which is editable, some
of which is not. The idea here is that the user can look
at a page with a scrolling 'window'. Move through the
editable HTML textboxes in the datagrid displayed in the
scrolling widow, then save all changes en-mass. This is
achieved, the datagrid having some zero width columns
which hold the original values that were in the editable
text boxes also. Basically, each editable field is
retrieved twice from the database, one is displayed as
editable to the user, one is hidden but holds the original
value.
I can achieve a PostBack event for the src of the IFrame
thru' javascript on either an asp.Net or HTML control.
In the Page Load event of the src of the IFrame, I
retrieve the ID values from the datagrid, iterate through
them, getting the editable and original values from the
datagrid, comparing them and saving records where there is
a difference. However, here I have an od issue.
On some machines, sometimes changes aren't saved. I cannot
replicate this on my dev machine, (win 2000 server) or on
a win 95 machine located close to me. It is frequently but
inconsistently replicable on a number of Win NT machines
some 500 miles away from me and on a win xp pro machine
also that distance away. It cannot be replicated on a Win
2003 server .Net development machine that is that
geographically seperated from me. NB: My dev machine is
acting as the Web Server.
The Page_Load event of the IFrame src is below.
<CODE>
private void Page_Load(object sender,
System.EventArgs e)
{/* Validate authentic users */
try
{
if (Session
["Authd"].ToString() == "true")
{
try
{
if (Session
["Role"].ToString() == "compliance")
{
}
else
{
Server.Transfer("frmLogin.aspx");
}
}
catch
(NullReferenceException)
{
Session
["Authd"] = "false";
Server.Transfer("frmLogin.aspx");
}
}
else if (Session
["Authd"].ToString() == "false")
{
Server.Transfer
("frmLogin.aspx");
}
else
{
Session["Authd"]
= "false";
Server.Transfer
("frmLogin.aspx");
}
}
catch (NullReferenceException)
{
Session["Authd"] = "false";
Server.Transfer
("frmLogin.aspx");
}
if (IsPostBack)
{
string[] ID = Request.Form
["txtID"].ToString().Split (',');
int i = 0;
if (Session
["PositionChange"] != null)
{
Session.Add
("PositionChange",0);
}
string MonthlyPeriod =
Dates.GetCCYYMM(DateTime.Now.ToLocalTime());
string UserName = Session
["UserName"].ToString();
for (i=0;i< ID.Length ;i++)
{
// try
// {
int CPID =
Convert.ToInt32(ID);
double
GasPayment = Convert.ToDouble(Request.Form["txtGasPayment"
+ ID].ToString());
double
TotalGasPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsGas" + ID].ToString());
double
ElectricityPayment = Convert.ToDouble(Request.Form
["txtElectricityPayment" + ID].ToString());
double
TotalElectricityPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsElectricity" + ID].ToString());
double
OtherPayment = Convert.ToDouble(Request.Form
["txtOtherPayment" + ID].ToString());
double
TotalOtherPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsOther" + ID].ToString());
double
Overdue = Convert.ToDouble(Request.Form["txtOutstanding" +
ID].ToString());
double
TotalOverdue = Convert.ToDouble(Request.Form
["txtTotalOutstanding" + ID].ToString());
int
PositionChange = Convert.ToInt32(Session
["PositionChange"].ToString());
if
(GasPayment != TotalGasPayments)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double PaymentAmount = GasPayment-TotalGasPayments;
string strSQL = "proc_UpdateFuelPayments " +
"@CPID = " + CPID + ", " +
"@Commodity = 1, " +
"@TotalAmount = " + GasPayment + ", " +
"@PaymentAmount = " + PaymentAmount + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@AuditUser = '" + UserName + "'";
SqlCommand InsertGasPayment = new SqlCommand
(strSQL, cnSQLLogin);
InsertGasPayment.Connection.Open();
InsertGasPayment.ExecuteNonQuery();
InsertGasPayment.Connection.Close();
}
if
(ElectricityPayment != TotalElectricityPayments)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double PaymentAmount = ElectricityPayment-
TotalElectricityPayments;
string strSQL = "proc_UpdateFuelPayments " +
"@CPID = " + CPID + ", " +
"@Commodity = 2, " +
"@TotalAmount = " + ElectricityPayment + ", " +
"@PaymentAmount = " + PaymentAmount + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@AuditUser = '" + UserName + "'";
SqlCommand InsertElectricityPayment = new
SqlCommand(strSQL, cnSQLLogin);
InsertElectricityPayment.Connection.Open();
InsertElectricityPayment.ExecuteNonQuery();
InsertElectricityPayment.Connection.Close();
}
if
(OtherPayment != TotalOtherPayments)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double PaymentAmount = OtherPayment-
TotalOtherPayments;
string strSQL = "proc_UpdateFuelPayments " +
"@CPID = " + CPID + ", " +
"@Commodity = 3, " +
"@TotalAmount = " + OtherPayment + ", " +
"@PaymentAmount = " + PaymentAmount + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@AuditUser = '" + UserName + "'";
SqlCommand InsertOtherPayment = new SqlCommand
(strSQL, cnSQLLogin);
InsertOtherPayment.Connection.Open();
InsertOtherPayment.ExecuteNonQuery();
InsertOtherPayment.Connection.Close();
}
if
(Overdue != TotalOverdue)
{
if
(Session["PositionChange"] != null)
{
Session["PositionChange"] = Convert.ToInt32(Session
["PositionChange"].ToString()) + 1;
}
else
{
Session.Add("PositionChange",1);
}
double Difference = Overdue - TotalOverdue;
string strSQL = "proc_UpdateOverdue " +
"@CPID = " + CPID + ", " +
"@MonthlyPeriod = '" + MonthlyPeriod + "', " +
"@overdue = " + Overdue + ", " +
"@Difference = " + Difference + ", " +
"@AuditUser = '" + UserName + "'";
SqlCommand UpdateOverdue = new SqlCommand(strSQL,
Connection.Connect());
UpdateOverdue.Connection.Open();
UpdateOverdue.ExecuteNonQuery();
UpdateOverdue.Connection.Close();
}
if
(PositionChange < Convert.ToInt32(Session
["PositionChange"].ToString()))
{
string strSQL = "UPDATE tbl_CounterpartyCalcs " +
"SET BalanceDue = COALESCE(((cpc.Overdue +
cpc.DueThisMonth) - cpc.PaymentsMadeReceived),0) " +
"FROM tbl_CounterpartyCalcs cpc " +
"WHERE cpc.CounterpartyId = " + CPID + " " +
"AND cpc.MonthlyPeriod = '" + MonthlyPeriod + "'";
SqlCommand BalanceDue = new SqlCommand(strSQL,
Connection.Connect());
BalanceDue.Connection.Open();
BalanceDue.ExecuteNonQuery();
BalanceDue.Connection.Close();
strSQL = "EXEC sp_Calc_Exposure_CPT " +
"@pFutureYears = 2, " +
"@pCPT = " + CPID + ", " +
"@Result = 0";
SqlCommand UpdateCPPosition = new SqlCommand
(strSQL, cnSQLLogin);
UpdateCPPosition.Connection.Open();
UpdateCPPosition.ExecuteNonQuery();
UpdateCPPosition.Connection.Close();
}
// }
// catch (Exception)
// {
//
Connection.CloseConnection(cnSQLLogin);
// }
}
Session.Add
("PopulateCommodity",0);
}
// Put user code to initialize the
page here
daPayments.SelectCommand.CommandText = "EXEC
proc_Select_PaymentsDue @Commodity = " + Session
["PopulateCommodity"].ToString();
daPayments.SelectCommand.Connection = cnSQLLogin;
daPayments.Fill
(dsNewPayment.tbl_Payment);
Session.Add("PopulateCommodity",0);
// Bind MyDataGrid to the DataSet
DataView s = new DataView
(dsNewPayment.tbl_Payment);
dgPayments.DataSource = s;
dgPayments.DataBind();
}
</CODE>
It validates the user, checks if this is a postback event,
and if it is validdates and saves changes between records,
then reloads the data.
Does anyone have any clues, or is it possible, as I
suspect, that on occassion my error is being caused by the
Top level page with the IFrame on it doing it's postback
first, which I think would simply refresh the data on the
IFrame src as it wouldn't be a PostBack for this page.
This would then postback after the first page and of
course there are no changes to the data as it's just been
reloaded from the database...
....or could this just be an IE bug, or something else
again...
....all help appreciated.