public class Class1
    {
        int myInt;        public int GetInt
        {
            get { return myInt; }
        }
        public int SetInt
        {
            set { myInt = value; }
        } 
    }以上是类文件.
************************************************************************        protected void Button1_Click(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            c1.SetInt = 100;
            Response.Redirect("WebForm2.aspx");
        }以上是WebForm1.aspx 的文件.
*********************************************        protected void Page_Load(object sender, EventArgs e)
        {
            Class1 c2 = new Class1();
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alt1", "alert('" + c2 .GetInt + "');", true);
        }以上是WebForm2.aspx 的文件.
为什么取到c2 .GetInt是0, 错在哪里啊?

解决方案 »

  1.   

    你的c1和c2都是Class1的不同实例,c2里当然取不到c1的值了。
      

  2.   

        public class Class1 
        { 
            public static int myInt = 0;         public static int GetInt 
            { 
                get { return myInt; } 
            } 
            public static int SetInt 
            { 
                set { myInt = value; } 
            } 
        } 这样直接调用,不用实例化了,试试。
      

  3.   

    你要取的myint根本没有值 怎么取?
      

  4.   

    成功没?我试了下可以的。WebForm1.aspx:
            protected void Button1_Click(object sender, EventArgs e)
            {
                Class1.SetInt = 100;
                Response.Redirect("WebForm2.aspx");
            }
    WebForm2.aspx
            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Write(Class1.GetInt);
            }
      

  5.   

    你当前这个问题是解决了,但你还要注意,静态成员在ASP.NET中是Application级的,也就是说所有站点用户共享这一个成员的值。