I have this question many times and bored, trying to find a good solution. I don’t understand why microsoft does not include a method that can easily determine the page display mode: “normal display” or “development mode”. He has a lot of tips for checking different variables, but he cannot say for sure that a page in design is on different types of pages (web page page and wiki page) and on the reverse side or not.
I'm finally tired, and I'm writing this:
public static bool IsDesignTime()
{
if (SPContext.Current.IsDesignTime) return true;
if (HttpContext.Current.Request.QueryString["DisplayMode"] != null)
return true;
var page = HttpContext.Current.Handler as Page;
if(page == null) return false;
var inDesign = page.Request.Form["MSOLayout_InDesignMode"];
var dispMode = page.Request.Form["MSOSPWebPartManager_DisplayModeName"];
var wikiMode = page.Request.Form["_wikiPageMode"];
var we = page.Request.Form["ctl00$PlaceHolderMain$btnWikiEdit"];
if (inDesign == null & dispMode == null) return false;
if (we == "edit") return true;
if (page is WikiEditPage & page.IsPostBack & inDesign == "" & dispMode == "Browse" & wikiMode == "") return false;
if (inDesign == "" & dispMode == "Browse" & (wikiMode == null | wikiMode == "")) return false;
if (inDesign == "0" & dispMode == "Browse") return false;
return true;
}
Does anyone have a better solution?
source
share