Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PostBack IFrame src Issue

Status
Not open for further replies.

Rhys666

Programmer
May 20, 2003
1,106
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[&quot;Authd&quot;].ToString() == &quot;true&quot;)
{
try
{
if (Session[&quot;Role&quot;].ToString() == &quot;compliance&quot;)
{
}
else
{
Server.Transfer(&quot;frmLogin.aspx&quot;);
}
}
catch (NullReferenceException)
{
Session[&quot;Authd&quot;] = &quot;false&quot;;
Server.Transfer(&quot;frmLogin.aspx&quot;);
}
}
else if (Session[&quot;Authd&quot;].ToString() == &quot;false&quot;)
{
Server.Transfer(&quot;frmLogin.aspx&quot;);
}
else
{
Session[&quot;Authd&quot;] = &quot;false&quot;;
Server.Transfer(&quot;frmLogin.aspx&quot;);
}
}
catch (NullReferenceException)
{
Session[&quot;Authd&quot;] = &quot;false&quot;;
Server.Transfer(&quot;frmLogin.aspx&quot;);
}

if (IsPostBack)
{
string[] ID = Request.Form[&quot;txtID&quot;].ToString().Split (',');
int i = 0;

if (Session[&quot;PositionChange&quot;] != null)
{
Session.Add(&quot;PositionChange&quot;,0);
}

string MonthlyPeriod = Dates.GetCCYYMM(DateTime.Now.ToLocalTime());
string UserName = Session[&quot;UserName&quot;].ToString();
for (i=0;i< ID.Length ;i++)
{
// try
// {
int CPID = Convert.ToInt32(ID);
double GasPayment = Convert.ToDouble(Request.Form[&quot;txtGasPayment&quot; + ID].ToString());
double TotalGasPayments = Convert.ToDouble(Request.Form[&quot;txtTotalPaymentsGas&quot; + ID].ToString());
double ElectricityPayment = Convert.ToDouble(Request.Form[&quot;txtElectricityPayment&quot; + ID].ToString());
double TotalElectricityPayments = Convert.ToDouble(Request.Form[&quot;txtTotalPaymentsElectricity&quot; + ID].ToString());
double OtherPayment = Convert.ToDouble(Request.Form[&quot;txtOtherPayment&quot; + ID].ToString());
double TotalOtherPayments = Convert.ToDouble(Request.Form[&quot;txtTotalPaymentsOther&quot; + ID].ToString());
double Overdue = Convert.ToDouble(Request.Form[&quot;txtOutstanding&quot; + ID].ToString());
double TotalOverdue = Convert.ToDouble(Request.Form[&quot;txtTotalOutstanding&quot; + ID].ToString());
int PositionChange = Convert.ToInt32(Session[&quot;PositionChange&quot;].ToString());

if (GasPayment != TotalGasPayments)
{
if (Session[&quot;PositionChange&quot;] != null)
{
Session[&quot;PositionChange&quot;] = Convert.ToInt32(Session[&quot;PositionChange&quot;].ToString()) + 1;
}
else
{
Session.Add(&quot;PositionChange&quot;,1);
}

double PaymentAmount = GasPayment-TotalGasPayments;
string strSQL = &quot;proc_UpdateFuelPayments &quot; +
&quot;@CPID = &quot; + CPID + &quot;, &quot; +
&quot;@Commodity = 1, &quot; +
&quot;@TotalAmount = &quot; + GasPayment + &quot;, &quot; +
&quot;@PaymentAmount = &quot; + PaymentAmount + &quot;, &quot; +
&quot;@MonthlyPeriod = '&quot; + MonthlyPeriod + &quot;', &quot; +
&quot;@AuditUser = '&quot; + UserName + &quot;'&quot;;
SqlCommand InsertGasPayment = new SqlCommand(strSQL, cnSQLLogin);
InsertGasPayment.Connection.Open();
InsertGasPayment.ExecuteNonQuery();
InsertGasPayment.Connection.Close();
}

if (ElectricityPayment != TotalElectricityPayments)
{
if (Session[&quot;PositionChange&quot;] != null)
{
Session[&quot;PositionChange&quot;] = Convert.ToInt32(Session[&quot;PositionChange&quot;].ToString()) + 1;
}
else
{
Session.Add(&quot;PositionChange&quot;,1);
}
double PaymentAmount = ElectricityPayment-TotalElectricityPayments;

string strSQL = &quot;proc_UpdateFuelPayments &quot; +
&quot;@CPID = &quot; + CPID + &quot;, &quot; +
&quot;@Commodity = 2, &quot; +
&quot;@TotalAmount = &quot; + ElectricityPayment + &quot;, &quot; +
&quot;@PaymentAmount = &quot; + PaymentAmount + &quot;, &quot; +
&quot;@MonthlyPeriod = '&quot; + MonthlyPeriod + &quot;', &quot; +
&quot;@AuditUser = '&quot; + UserName + &quot;'&quot;;
SqlCommand InsertElectricityPayment = new SqlCommand(strSQL, cnSQLLogin);
InsertElectricityPayment.Connection.Open();
InsertElectricityPayment.ExecuteNonQuery();
InsertElectricityPayment.Connection.Close();
}

if (OtherPayment != TotalOtherPayments)
{
if (Session[&quot;PositionChange&quot;] != null)
{
Session[&quot;PositionChange&quot;] = Convert.ToInt32(Session[&quot;PositionChange&quot;].ToString()) + 1;
}
else
{
Session.Add(&quot;PositionChange&quot;,1);
}
double PaymentAmount = OtherPayment-TotalOtherPayments;

string strSQL = &quot;proc_UpdateFuelPayments &quot; +
&quot;@CPID = &quot; + CPID + &quot;, &quot; +
&quot;@Commodity = 3, &quot; +
&quot;@TotalAmount = &quot; + OtherPayment + &quot;, &quot; +
&quot;@PaymentAmount = &quot; + PaymentAmount + &quot;, &quot; +
&quot;@MonthlyPeriod = '&quot; + MonthlyPeriod + &quot;', &quot; +
&quot;@AuditUser = '&quot; + UserName + &quot;'&quot;;
SqlCommand InsertOtherPayment = new SqlCommand(strSQL, cnSQLLogin);
InsertOtherPayment.Connection.Open();
InsertOtherPayment.ExecuteNonQuery();
InsertOtherPayment.Connection.Close();
}

if (Overdue != TotalOverdue)
{
if (Session[&quot;PositionChange&quot;] != null)
{
Session[&quot;PositionChange&quot;] = Convert.ToInt32(Session[&quot;PositionChange&quot;].ToString()) + 1;
}
else
{
Session.Add(&quot;PositionChange&quot;,1);
}
double Difference = Overdue - TotalOverdue;
string strSQL = &quot;proc_UpdateOverdue &quot; +
&quot;@CPID = &quot; + CPID + &quot;, &quot; +
&quot;@MonthlyPeriod = '&quot; + MonthlyPeriod + &quot;', &quot; +
&quot;@Overdue = &quot; + Overdue + &quot;, &quot; +
&quot;@Difference = &quot; + Difference + &quot;, &quot; +
&quot;@AuditUser = '&quot; + UserName + &quot;'&quot;;
SqlCommand UpdateOverdue = new SqlCommand(strSQL, Connection.Connect());
UpdateOverdue.Connection.Open();
UpdateOverdue.ExecuteNonQuery();
UpdateOverdue.Connection.Close();
}

if (PositionChange < Convert.ToInt32(Session[&quot;PositionChange&quot;].ToString()))
{
string strSQL = &quot;UPDATE tbl_CounterpartyCalcs &quot; +
&quot;SET BalanceDue = COALESCE(((cpc.Overdue + cpc.DueThisMonth) - cpc.PaymentsMadeReceived),0) &quot; +
&quot;FROM tbl_CounterpartyCalcs cpc &quot; +
&quot;WHERE cpc.CounterpartyId = &quot; + CPID + &quot; &quot; +
&quot;AND cpc.MonthlyPeriod = '&quot; + MonthlyPeriod + &quot;'&quot;;
SqlCommand BalanceDue = new SqlCommand(strSQL, Connection.Connect());
BalanceDue.Connection.Open();
BalanceDue.ExecuteNonQuery();
BalanceDue.Connection.Close();

strSQL = &quot;EXEC sp_Calc_Exposure_CPT &quot; +
&quot;@pFutureYears = 2, &quot; +
&quot;@pCPT = &quot; + CPID + &quot;, &quot; +
&quot;@Result = 0&quot;;

SqlCommand UpdateCPPosition = new SqlCommand(strSQL, cnSQLLogin);
UpdateCPPosition.Connection.Open();
UpdateCPPosition.ExecuteNonQuery();
UpdateCPPosition.Connection.Close();
}
// }
// catch (Exception)
// {
// Connection.CloseConnection(cnSQLLogin);
// }
}

Session.Add(&quot;PopulateCommodity&quot;,0);
}

// Put user code to initialize the page here
daPayments.SelectCommand.CommandText = &quot;EXEC proc_Select_PaymentsDue @Commodity = &quot; + Session[&quot;PopulateCommodity&quot;].ToString();
daPayments.SelectCommand.Connection = cnSQLLogin;
daPayments.Fill(dsNewPayment.tbl_Payment);
Session.Add(&quot;PopulateCommodity&quot;,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.

Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
Sorted it. I was correct, there was no consistency between which order the two forms post back events were running. On some ocasions the top level forms event was running first, refreshing the data in the iframe's src, which then posted back and found no data had ben changed, obviously as it had just been reloaded from the data base, while on other ocassions the iframe's src form was posting back first, validating and saving changes and then the top level form was posting back.

Simply changed the asp.Net control for an HTML Control (runat=&quot;server&quot;), which didn't automatically post back the top level form, just triggered the client side javascript to post back the iframe's src form.

AAAhhhh, happy now, and so are a few other people!

Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top