468,140 Members | 1,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

PostBack IFrame src issue

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[i]);
double
GasPayment = Convert.ToDouble(Request.Form["txtGasPayment"
+ ID[i]].ToString());
double
TotalGasPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsGas" + ID[i]].ToString());
double
ElectricityPayment = Convert.ToDouble(Request.Form
["txtElectricityPayment" + ID[i]].ToString());
double
TotalElectricityPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsElectricity" + ID[i]].ToString());
double
OtherPayment = Convert.ToDouble(Request.Form
["txtOtherPayment" + ID[i]].ToString());
double
TotalOtherPayments = Convert.ToDouble(Request.Form
["txtTotalPaymentsOther" + ID[i]].ToString());
double
Overdue = Convert.ToDouble(Request.Form["txtOutstanding" +
ID[i]].ToString());
double
TotalOverdue = Convert.ToDouble(Request.Form
["txtTotalOutstanding" + ID[i]].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.
Nov 17 '05 #1
1 4177
Hello,

When the parent webform is postback, its child webform (in iFrame) wouldn't
be post back, it only be reloaded. Anyway, since the problem was only found
on several computer, this didn't seem to be the root cause.

I found you have some try..catch statement in the code, so that user may
not see a raw error. The problem may also occur when writng data to
database. I suggest may add some debug code into the Catch statement. For
example, add the error information to System event log.For detail on this,
you may refer to :

HOW TO: Write to an Event Log by Using Visual C# .NET
http://support.microsoft.com/default...;EN-US;Q307024

You also can log the client's IP and computer name to see if the error came
from the particualr computers:

Request.UserHostName
Request.UserHostAddress

Hope this help.

Luke
Microsoft Online Partner Support

Get Secure! www.microsoft.com/security)
This posting is provided "AS IS", with no warranties, and confers no

ights.)

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jason | last post: by
3 posts views Thread by Guogang | last post: by
4 posts views Thread by Richard St?en | last post: by
2 posts views Thread by Carter | last post: by
3 posts views Thread by Ashish | last post: by
4 posts views Thread by Mervin Williams | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.