我有一个用户控件。是否有某种方法可以获取usercontrol可用的页面?
答案 0 :(得分:3)
在你的usercontrol中编写这个方法
protected void MyMethod()
{
Page myParent = this.Page;
...
}
答案 1 :(得分:1)
您需要Page
属性。
如果您需要回写某个类型的页面,则必须进行转换:
var myUserPage = Page as MyCustomUserPageClass;
if (myUserPage != null) {
myUserPage.Foo = "bar";
}