c# ,webforms,vs2003, frames

i have a web form that have two frames top frame and main frame
and the top frame contains all the links to the pages wich is loaded in the main frame
and lets say i have 2 web forms (webform1 & webform 2.

my problem is every time i change web form using the links at run time what ever the veriable values that was left on the other page nerver changes to thair original state like when the page is loaded at the fist time

lets say i have a cal culculation in the fist webform1 which is dis played on the page load and the second one the same way as the first
when the fist page loads it gives me the answer =3

and when i go to the second page and it gives me the answer =3
again
when i come back to the first one it gives me the answer =6 and go to the second it gives me the answer =6

whey is this happening why arn't the variables getting re-initialized

please help m

webform1 (statrting form)

namespace sen
{

public class Products : System.Web.UI.Page
{
int total=0;
int var1=1;
int var2=2;
private void Page_Load(object sender, System.EventArgs e)
{
int total=var1+var2;
lblno.Text=total.ToString();
}
}
}

webform2

namespace sen
{

public class Products : System.Web.UI.Page
{
int total=0;
int var1=1;
int var2=2;
private void Page_Load(object sender, System.EventArgs e)
{
[COLOR="Red"]int total=var1+var2;[/COLOR]
lblno.Text=total.ToString();
}
}
}

Edited 3 Years Ago by pyTony: fixed formatting

c# ,webforms,vs2003, frames

i have a web form that have two frames top frame and main frame
and the top frame contains all the links to the pages wich is loaded in the main frame
and lets say i have 2 web forms (webform1 & webform 2.

my problem is every time i change web form using the links at run time what ever the veriable values that was left on the other page nerver changes to thair original state like when the page is loaded at the fist time

lets say i have a cal culculation in the fist webform1 which is dis played on the page load and the second one the same way as the first
when the fist page loads it gives me the answer =3

and when i go to the second page and it gives me the answer =3
again
when i come back to the first one it gives me the answer =6 and go to the second it gives me the answer =6

whey is this happening why arn't the variables getting re-initialized

please help me

webform1 (statrting form)

namespace sen
{

public class Products : System.Web.UI.Page
{
int total=0;
int var1=1;
int var2=2;
private void Page_Load(object sender, System.EventArgs e)
{
int total=var1+var2;
lblno.Text=total.ToString();
}
}
}

webform2

namespace sen
{

public class Products : System.Web.UI.Page
{
int total=0;
int var1=1;
int var2=2;
private void Page_Load(object sender, System.EventArgs e)
{
int total=var1+var2;
lblno.Text=total.ToString();
}
}
}

Ok, dude i dont quite get your question, and i'm not much of an ASP person, but from what i can tell. there is a bug in your code since your field total decleared as ant int is not updated by any code thus will remain the same. try not re-declaring it again in the page_load method.

ex.

class calc
{
int total = 0;

static void Page_Load(params..)
{
  int lval1 = 2;
  int rval2 = 5;
  total = lval1 + rval2;//you dont have to re-declare it in this method since its globally accessible
}
}

Edited 3 Years Ago by pyTony: fixed formatting

ahh im verry sorry about that its not like it should be like

webform1 (statrting form)

namespace sen
{

public class Products : System.Web.UI.Page
{
static int total=0;
int var1=1;
int var2=2;
private void Page_Load(object sender, System.EventArgs e)
{
total=var1+var2;
lblno.Text=total.ToString();
}
}
}

********************************************************************

webform2

namespace sen
{

public class Products : System.Web.UI.Page
{
static int total=0;
int var1=1;
int var2=2;
private void Page_Load(object sender, System.EventArgs e)
{
total=var1+var2;
lblno.Text=total.ToString();
}
}
}

u see what happen is when i change pages the amount in total variable dose not chanege back to 0 when the page is loaded it still contains the value that was assinged to it by the previous calculation

That is because you have delared it static.
Remove static from the total delcaration and see what happens.

Edited 6 Years Ago by nick.crane: n/a

This article has been dead for over six months. Start a new discussion instead.