user339160
user339160

Reputation:

How to get the page calling the usercontrol

I have a user control .Is there some way to get the page in which usercontrol is available ?

Upvotes: 1

Views: 557

Answers (2)

Pranay Rana
Pranay Rana

Reputation: 176956

In your usercontrol write this method

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

    ... 
}

alt text

Upvotes: 3

Dave Markle
Dave Markle

Reputation: 97821

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

Upvotes: 1

Related Questions