1
votes

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.

2

2 Answers

3
votes

if (this.WebPartManager.GetType().Name == "SPWebPartManager") { // SharePoint } else { // Not SharePoint }

1
votes

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