[英]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.