开发者

How to get the page calling the usercontrol

开发者 https://www.devze.com 2023-01-14 12:28 出处:网络
I have a user control .Is there some way to get the p开发者_开发技巧age in which usercontrol is available ?In your usercontrol write this method

I have a user control .Is there some way to get the p开发者_开发技巧age in which usercontrol is available ?


In your usercontrol write this method

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

    ... 
}

How to get the page calling the usercontrol


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";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消