

























在asp.net网页中或者BasePage基类中,你有写上一个public方法,2个参数,传入字符类型和用户控件。
public void XYZ(string myStr, UserControl myControlascx) { //这里想访问用户控件的函数 }
想在aspx.cs调用上面的方法,此方法内能调用到用户控件的函数。
简单的实现方法,写个interface,
public interface IFun { void Fun1(string str); //方法 string Fun2(string str); //返回函数 }
现在,我回到最开始提及的XYZ()方法,把它写完整,
public void XYZ(string myStr, UserControl myControlascx) { IFun obj = (IFun)myControlascx; obj.Fun1(myStr); //把字符串传给方法。 obj.Fun2(myStr); //呼叫返回式方法。 }
在你的aspx.cs中,去实现,
protected void Page_Load(object sender, EventArgs e) { XYZ("Test Message", this.MyControl); }
这样子,就可以调用到用户控件的函数了。
参考并试试....
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。