用户控制C#.NET内的公共方法 [英] Public Methods inside User control c# .net

查看:201
本文介绍了用户控制C#.NET内的公共方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从页面中调用用户控件的公共方法?

How can invoke user control's public method from within the page?

我动态加载控件中的OnInit在page.Any想法?出于某种原因,我得到,指出该方法不存在,即使它是公共的生成错误。开始认为用户控件不值得所有的麻烦。

I load the control dynamically inside OnInit on the page.Any ideas? For some reason I am getting a build error that says that the method doesn't exist, even though it's public. Starting to think that user controls are not worth all the hassle.

推荐答案

您已经说过

Control fracTemplateCtrl = 
   (FracTemplateCtrl)LoadControl("FracTemplateCtrl.ascx")
fracTemplateCtrl.TestMethod();

您需要说

FracTemplateCtrl fracTemplateCtrl =
   (FracTemplateCtrl)LoadControl("FracTemplateCtrl.ascx")
fracTemplateCtrl.TestMethod();

注意 fracTemplateCtrl被声明为 A FracTemplateCtrl ,让视觉工作室知道它有一个 TestMethod的()。当它被声明为控制,视觉工作室不能使这种假设。

Note that fracTemplateCtrl is declared as a FracTemplateCtrl, so visual studio knows that it has a TestMethod(). When it is declared as a Control, visual studio can't make this assumption.

这篇关于用户控制C#.NET内的公共方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆