protected void Page_Load(object sender, EventArgs e)
    {
         if (Page.IsPostBack)
        {        }
        else
        {
            Label lbl_message = new Label();
            lbl_message.ID = "fe";
            lbl_message.Text = "hell world";
            PlaceHolder1.Controls.Add(lbl_message);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label lbl;
        lbl =(Label)Page.FindControl("fe");
        lbl=(Label)this.FindControl("fe");
         lbl.Text = "找到了";
    }
当我点 BUTTON1的时候执行到 lbl.Text = "找到了";产生错误: 未将对象引用设置到对象的实例(使用new关键字产生实例)。
怎样解决这个问题?

解决方案 »

  1.   

    原因:Page.IsPostBack 时 没有生成,导致读取不到,解决:
    protected void Page_Load(object sender, EventArgs e)
        {
                Label lbl_message = new Label();
                lbl_message.ID = "fe";
                lbl_message.Text = "hell world";
                PlaceHolder1.Controls.Add(lbl_message);    }
    但是在内容页里仍然读不到 母版页/内容页
      

  2.   

    此为soho广告,不诚勿进www.idealworkroom.com
      

  3.   

    http://msdn2.microsoft.com/zh-CN/library/c8y19k6h.aspx
    参考 已编程方式使用母版页