views:

34

answers:

2

I have a suite of webpart controls that I maintain and develop for our main Sharepoint offerings. I also have an Asp .Net website which acts as a test suite for selenium scripts and unit tests.

How can I determine from the web part code server code whether the control is currently being hosted in a Sharepoint page or whether the webpart is being hosted on a normal ASP .Net page? I'm looking to prepopulate some of the webpart properties with defaults but only when they exist in the ASP .Net page environment.

+3  A: 

Hi Brian

if (this.WebPartManager.GetType().Name == "SPWebPartManager")
{
// SharePoint
}
else
{
// Not SharePoint
}
Per Jakobsen
Excellent, just what I was looking for. Thanks. :-)
Brian Scott
+1  A: 

You can probably test SPContext.Current.Web to be null

Vladi Gubler
@Vladi: That's a good suggestion as well. I've went with Per's answer though.
Brian Scott