日期:2014-05-18  浏览次数:20370 次

获取Panel内字符的长度与内容
现有两个文件: UserControl.ascx, Test.Aspx

1.UserControl.ascx页面为一段文字,如:“aaaaaaaaaaaaaaaaaaaaaaaaaaa.......aaaaaaaaaa”

2.在ASPX页面托放一个Panel,

 protected void Page_Load(object sender, EventArgs e)
  {
  this.Panel1.Controls.Add(LoadControl("UserControl.ascx"));
  }

---------------------------
现如何获取Panel1内字符的长度与内容呢?

------解决方案--------------------
C# code

        Control c = LoadControl("WebUserControl.ascx");
        this.Panel1.Controls.Add(c);
        foreach (Control con in c.Controls)
        {
            if (con is LiteralControl)
            {
                LiteralControl lc = con as LiteralControl;
                Response.Write(lc.Text+",长度:"+lc.Text.Length.ToString());
            }
        }