954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

web forms help .............................................

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();
}
}
}

kalpa23
Light Poster
41 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

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
}
}

mshauny
Junior Poster in Training
62 posts since Jan 2010
Reputation Points: 35
Solved Threads: 6
 

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();
}
}
}

kalpa23
Light Poster
41 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

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

kalpa23
Light Poster
41 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

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

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: