简体   繁体   中英

How to get the page calling the usercontrol

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

In your usercontrol write this method

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

    ... 
}

替代文字

You want the Page property.

If you need to write back to a page of a certain type, you'll have to cast:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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