一个TextBox1,一个Button1,在Page_Load里 赋值 ,更改TextBox1里的值,点按钮时取值.发现在还是"1234"...求解.. protected void Page_Load(object sender, EventArgs e)
        {
            TextBox1.Text = "1234";
        }        protected void Button1_Click(object sender, EventArgs e)
        {
            string aaa = TextBox1.Text;
            Response.Write(aaa);
        }

解决方案 »

  1.   


    if(!page.ispostbak)
    {
           TextBox1.Text = "1234";
    }
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
            {
                if(!IsPostBack)TextBox1.Text = "1234";
            }        protected void Button1_Click(object sender, EventArgs e)
            {
                string aaa = TextBox1.Text;
                Response.Write(aaa);
            }
    点击按钮页面回传重新赋值
      

  3.   

    protected void Page_Load(object sender, EventArgs e)
    {
         if(!IsPostBack)
         {
           TextBox1.Text = "1234";
         }
    }        protected void Button1_Click(object sender, EventArgs e)
            {
                string aaa = TextBox1.Text;
                Response.Write(aaa);
            }
    因为在你赋值完毕,点Button1取值的时候,不加IsPostBack,他还是进入了page_load执行了赋值代码
    ,"!IsPostBack"是初始化页面的时候才执行的,你调试就可以知道原因的