惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

博客园 - Insus.NET

Vue3实现拖放式上传 拖放式上传 实现MultipartStreamProvider经Web API上传文档或图片 文件上传和表单字段混合提交 在HttpContext.Current返回null时如何操作 angularjs根据类型动态加载组件 angularjs获取数据服务 扫一扫直连WiFi二维码 User Profile Service 服务未能登录 Visual Studio2026创建Vue项目 安装与配置node.js HTTP Error 403.14 - Forbidden VisualStudio2026回滚上一版本 消息认证码(加强) 网站无法使用插值字符串语法 HMAC(Hash-based Message Authentication Code)认证示例 浏览器自动发送域凭据 企业内小网站兼用Windows验证登录 onblur事件改为监听处理 将警报消息改为吐司消息 内容有无变化OnBlur即时更新引起的问题与解决 混合式提高用户编辑与操作效率 光标离开文框后即刻更新 WebForm实现Web API JavaScript对GridView删除行后并重新给其数据绑定 把CS值传给JS使用 v2 确认信息confirm由C#后端移至javascript前端 无法发布网站Web Site JavaScript判断字符是否为decimal 点击单元格弹出窗口处理数据返回父页
访问用户控件的函数
Insus.NET · 2026-05-12 · via 博客园 - Insus.NET

在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); //返回函数
}

在你的用户控件中,实现这个接口,
2026-05-12_09-10-33

好吧,你那一个aspx网页想用到这个用户控件,拉进入即可。
2026-05-12_09-14-54


现在,我回到最开始提及的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);
}

这样子,就可以调用到用户控件的函数了。
参考并试试....