读书人

访问用户控件中的TextBox,该怎么解决

发布时间: 2012-02-08 19:52:21 作者: rapoo

访问用户控件中的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 作为一个属性展现出来 这样不就可以任意读写了嘛

读书人网 >asp.net

热点推荐