首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在asp.net中调用页面中的用户控件方法

如何在asp.net中调用页面中的用户控件方法
EN

Stack Overflow用户
提问于 2012-11-08 17:32:55
回答 2查看 8.9K关注 0票数 1

我在Usercontrol.ascx中有以下方法

代码语言:javascript
运行
复制
public void Flasmessage()
{
    popupmessage2.Visible = true;
    string strScript = "HideCtrl('" + popupmessage2.ClientID + "','15000')";

    Page.ClientScript.RegisterStartupScript(
      this.GetType(),
      Guid.NewGuid().ToString(),
      strScript,
      true);
}

我需要从另一个页面和另一个Usercontrol.ascx调用以下方法

EN

Stack Overflow用户

发布于 2012-11-08 17:38:24

您需要在页面上获取对UserControl实例的引用,然后调用该方法,如下所示:

代码语言:javascript
运行
复制
void Page_Load() {

    // do this if your control does not exist in your *.aspx file and needs to be manually added:
    MyUserControl control = (MyUserControl)LoadControl("MyUserControl.ascx");
    this.Controls.Add( control );

    // do this if your control already exists in your page as a named control
    MyUserControl control = (MyUserControl)FindControl("myUserControl");

    // do this in both cases, or if your UserControl exists as a field in your *.aspx-generated page class.
    control.MyMethod();

}
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13286217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档