Control ct= Page.LoadControl(yourcontrol);
TextBox tb=(TextBox)ct.FindControl("TextBOx1");
tb.Text="XX";

解决方案 »

  1.   

      谢谢 ,这个指的是动态加载的控件吧。我把WebUserControl2.ascx加载到页面中后,点击页面的button1后页面并不输出textbox中的字符,能看看下面这段代码吗
               protected  void Button1_Click(object sender, EventArgs e)
        {
            this.Page.LoadControl("WebUserControl2.ascx");
            WebUserControl2 user1;
            user1 =(WebUserControl2)this.LoadControl("WebUserControl2.ascx");
            TextBox tb = (TextBox)user1.FindControl("TextBox1");
                 string xingming = tb.Text;      
                 Response.Write(xingming);
        }
      

  2.   

    关键是你的userControl中的textbox要存储状态,当你的page_load()运行new userControl()的构造方法时,所有原来的状态都="" or null了,所以你必须在userControl中用viewstate存储状态才可以喔!!