public
void
SetLabel(
string
str)
{
this.Label1.Text = str; ;
}
ascx文件;
{
this.Label1.Text = str; ;
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
System.Web.UI.Page p = this.Page;
Type pageType = p.GetType();
MethodInfo mi = pageType.GetMethod("SetLabel");
mi.Invoke(p, new object[] { "你这个大猪猪!" });
}
2. 在自定义控件中定义这个控件的属性
{
System.Web.UI.Page p = this.Page;
Type pageType = p.GetType();
MethodInfo mi = pageType.GetMethod("SetLabel");
mi.Invoke(p, new object[] { "你这个大猪猪!" });
}
public
Control LabelText
{
get{return this.Label1.Text;}
}
3用FindControl方法寻找
{
get{return this.Label1.Text;}
}
Label lbl
=
(Label)WebUserControl1.FindControl(
"
Label1
"
);