繁体   English   中英

如何获取调用usercontrol的页面

[英]How to get the page calling the usercontrol

我有一个用户控件。有什么方法可以获得usercontrol可用的页面吗?

在您的usercontrol中编写此方法

protected void MyMethod()
{
    Page myParent = this.Page;

    ... 
}

替代文字

你想要Page属性。

如果您需要回写某个类型的页面,则必须进行转换:

var myUserPage = Page as MyCustomUserPageClass;
if (myUserPage != null) {
  myUserPage.Foo = "bar";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM