文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Calling a method in parent page & other user control from a user control

Calling a method in parent page & other user control from a user control

时间:2011-06-16  来源:hmloo

1.Calling a method in parent page.

Parent page method:
Public
void SetTxt(string txt1, string txt2)
{

}

User control:
private void Button1_Click(object sender, System.EventArgs e)
{
//Get the parent page
Page p = this.Page;
Type pageType
= p.GetType ();
//Get method
MethodInfo mi = pageType.GetMethod ("SetTxt");
// Parameter
mi.Invoke (p, new object [] {"parameter 1", "parameter 2"});
}
  

2. Calling a method in other user control

User control 1:
Public
void SetTxt(string txt1, string txt2)
{

}

User control
2:
private void Button1_Click(object sender, System.EventArgs e)
{
//Get the parent page
Page p = this.Page;
//Get the other controls
UserControl uc = p.FindControl ("UserControl1") as UserControl;
Type pageType
= uc.GetType ();
//Get method
MethodInfo mi = pageType.GetMethod ("SetTxt");
// Parameter
mi.Invoke (uc, new object [] {"parameter 1", "parameter 2"});
}

3. Set the properties between user controls

// Get the parent page
Page p = this.Page;
/ / Get the other controls
UserControl uc
= p.FindControl ("Usercontrol1") as UserControl;
Type pageType
= uc.GetType ();
PropertyInfo mi
= pageType.GetProperty ("property name");
mi.SetValue (uc,
"property value", null);

Note:

1. The method must be Public in parent page or other controls.

2. If you want to get the return value, please get the Invoke return value, it's an object, you can cast to your type.

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载