//===================================这是在aspx中 ClassA A = new ClassA(); public ClassA GetType() { return A; } //===================================这是在ascx中 MethodInfo GetA = Page.GetType().GetMethod("GetA"); B = (A)GetA.Invoke(Page, null);//ascx是放在aspx中的,
不好意思, 楼上的贴错了//===================================这是在aspx中 ClassA A = new ClassA(); public ClassA GetA() { return A; } //===================================这是在ascx中 MethodInfo GetA = Page.GetType().GetMethod("GetA"); ClassA B = (A)GetA.Invoke(Page, null);//ascx是放在aspx中的,
ClassA classA= new ClassA();
楼主啊,你到底是反射ClassA还是classA
//===================================这是在aspx中
ClassA A = new ClassA();
public ClassA GetType()
{
return A;
}
//===================================这是在ascx中
MethodInfo GetA = Page.GetType().GetMethod("GetA");
B = (A)GetA.Invoke(Page, null);//ascx是放在aspx中的,
ClassA A = new ClassA();
public ClassA GetA()
{
return A;
}
//===================================这是在ascx中
MethodInfo GetA = Page.GetType().GetMethod("GetA");
ClassA B = (A)GetA.Invoke(Page, null);//ascx是放在aspx中的,
你可以Debug一下:
bool isSameObj = Object.ReferenceEquals(A, B);关键是在你之前的判断中间是否发生Page的PostBack才进行的修改?注意:Page每次Postback都是一个新的对象,其中的类成员也都重新New过。