如何从另一个用户控件调用用户控件方法 [英] How to call a user control method from another user control
本文介绍了如何从另一个用户控件调用用户控件方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在页面下有两个用户控件U1和U2。在U1中我有一个公共方法刷新U1的所有控件。不,我想在U2中使用这种方法。
请帮忙。
谢谢和Reagrds
Mohd Wasif
Hi all,
I have two usercontrol as U1 and U2 under a page .In U1 I have a public method that refreshes all the controls of U1. No I want that methos in U2.
Please help.
Thanks & Reagrds
Mohd Wasif
推荐答案
void Page_Load() {
MyUserControl control = (MyUserControl)FindControl("myUserControl");
control.MyMethod();
}
尝试这样
将主页视为您的页面名称..
尝试使用此代码调用用户控件方法。
try like this
Consider Homepage as your Page Name..
try this code for calling the User control method.
typeof(HomePage).InvokeMember("ResetControls", System.Reflection.BindingFlags.InvokeMethod, null, this.Page, null);
主页中的
(这两个用户控件的容器页面)
创建一个方法 ResetControls();
in the HomePage( Container page for these 2 user control)
create a method as ResetControls ();
public void ResetControls ()
{
UserControl1.ResetControls();
}
这篇关于如何从另一个用户控件调用用户控件方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文