页面控件与用户控件之间的数据访问

asp

2012-04-26 16:46

用户控件 访问父页面控件的方法。。 

TextBox b2 = this.Parent.FindControl("TextBox1") as TextBox;   读取
        this.Button1.Text = b2.Text;

  (this.Parent.FindControl("Label1") as Label).Text = "哈哈哈哈哈";  修改

 

页面控件访问用户控件的方法

WebUserControl1 是用户控件的ID

 TextBox t2 = this.WebUserControl1.FindControl("TextBox1") as TextBox;     读取
  TextBox1.Text = t2.Text;

 

修改 都可以 k是用户控件名字  y是其中一个Label控件

  (this.FindControl("k").FindControl("y") as Label).Text = "xxxx";

 (Page.Form.FindControl("k").FindControl("y") as Label).Text = "原来可以修改";