because if you create a page object programmatically,caculate2 my2 = new caculate2(); the controls in your page are not hooked up to the variables, so labAdd and labSub are nulltry public class Caculate { caculate2 c2; public Caculate(caculate2 c) { c2 = c; } public int x,y,z;
public void Add() { z = x + y; c2.ListAdd(z.ToString()); } public void Sub() { z = x - y; c2.ListDel(z.ToString()); } } thenCaculate my = new Caculate(this);
急问为什么一直出现"异常详细信息: System.Web.HttpException: 响应在此上下文中不可用"
namespace test.test
{
public class caculate2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtA;
protected System.Web.UI.WebControls.TextBox txtB;
protected System.Web.UI.WebControls.Label labAdd;
protected System.Web.UI.WebControls.Label labSub;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
} private void Button1_Click(object sender, System.EventArgs e)
{
Caculate my = new Caculate();
my.x = int.Parse(txtA.Text.ToString());
my.y = int.Parse(txtB.Text.ToString());
my.Add();
my.Sub();
} public void ListAdd(string a)
{
labAdd.Text = a;
//为什么一直在这行提示:异常详细信息: System.Web.HttpException: 响应在此上下文中不可用。
} public void ListDel(string b)
{
labSub.Text = b;
}
} public class Caculate
{
public int x,y,z;
caculate2 my2 = new caculate2();
public void Add()
{
z = x + y;
my2.ListAdd(z.ToString());
}
public void Sub()
{
z = x - y;
my2.ListDel(z.ToString());
}
}
}
我已经找出了原因请大家帮我看看这个
急问为什么一直出现"异常详细信息: System.Web.HttpException: 响应在此上下文中不可用"也就是这个
http://community.csdn.net/Expert/topic/3135/3135013.xml?temp=.9680597
非常感谢
public class Caculate
{
caculate2 c2;
public Caculate(caculate2 c)
{
c2 = c;
} public int x,y,z;
public void Add()
{
z = x + y;
c2.ListAdd(z.ToString());
}
public void Sub()
{
z = x - y;
c2.ListDel(z.ToString());
}
}
thenCaculate my = new Caculate(this);