日期:2014-05-19  浏览次数:20491 次

访问用户控件中的TextBox
我制作了一个在线编辑器控件(ascx),需要在aspx页面上访问编辑器内容时出了问题,可以使用FindControl找到控件,但无法使用TextBox的属性如TextBox.Text,请问应该如何写?

public   partial   class   AddNews   :   System.Web.UI.Page
        {
                TextBox   newTextBox   =   null;
                protected   void   Page_Load(object   sender,   EventArgs   e)
                {
                        Control   MyControl   =   this.NewsEditor.FindControl( "MyTextBox ");
                        if   (MyControl   !=   null)
                        {
                                newTextBox   =   (TextBox)MyControl;
                                Response.Write( "it 's   not   null "   +   MyControl.Parent.ID   +   "   "   +   newTextBox.Text);
                        }
                        else
                        {
                                Response.Write( "it 's   null ");
                        }
                }
        }


现在newTextBox.Text为空,而用户控件里的TextBox.Text不为空。

------解决方案--------------------
你的在线编辑器 最好将你的那个TextBox 作为一个属性展现出来 这样不就可以任意读写了嘛