protected void Page_Load(object sender, EventArgs e)
    {        Response.Write(Label1.Text);
    }
  protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "hello world";
        
    }运行时点击一次button1 后label1即变为helloworld 而 Response.Write(Label1.Text)显示的却是label1
再点击一次才显示helloworld  不解中 难道点击button时先postback再执行事件 那label得值怎么变了

解决方案 »

  1.   

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write(Label1.Text);
        }
    }
      

  2.   

    if(!IsPOstBack)
    {
    Response.Write(Label1.Text);}
    页面回传
    IsPostBack是Page类有一个bool类型的属性,用来判断针对当前Form的请求是第一次还是非第一次请求。当IsPostBack=true时表示非第一次请求
      

  3.   

    先执行Page_Load,再执行Button1_Click的。  所以Page_Load中Label1.Text 的值还是label1。 在Button1_Click事件中,才改变了它的值。  
      

  4.   


    正解这个LZ要看下 页面的生命周期。。就明白了。。页面事件的执行顺序。
    Page_Load 事件 在 Button1_Click之前执行呢。。
    Page_Load 执行的时候 你那个 输出的是你那个 lable 的默认值 lable1
      

  5.   

    加上IsPostBack 就 OK 了 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write(Label1.Text);
        }
    }
      

  6.   

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write(Label1.Text);
        }
    }