Yogesh
Yogesh

Reputation: 67

How to determine the calling page in user control

I have a user control which is in common in two asp.net pages how to find out the parent page i dont want to use the page's title is there any concrete way to determine may be a page's class or any way else

I would like to do this

if (this.page == "pagename")
{
     //do this
}
else
{
     //do this
}

Upvotes: 1

Views: 625

Answers (3)

Md Nazmoon Noor
Md Nazmoon Noor

Reputation: 3307

Try this:

if (this.Page.GetType().Name.ToLower() == "pagename".Replace(".", "_").ToLower()) 
{ 
   //do this 
} 
else 
{ 
   //do this 
}

Upvotes: 0

Murali Murugesan
Murali Murugesan

Reputation: 22619

You can use this.Page in order to find the current page and use this.Page.GetType() if you are expecting class name

Upvotes: 2

C Sharper
C Sharper

Reputation: 8646

You can use:

Page myParentPage = this.Page;

In your method.

Upvotes: 0

Related Questions