Welcome to Comunidade Bloggers |create|it| Sign in | Join | Help

André Vala

SharePoint
Office
FAST Search Server
.Net

News

  • European SharePoint Community Awards 2012 Winner
    Locations of visitors to this page

    Comunidade Portuguesa de SharePoint

    View André Vala's profile on LinkedIn

    © André Vala and Create IT, 2006-2011. Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to André Vala and Create IT with appropriate and specific direction to the original content.

SharePoint Tip #15: Testing the Display Mode of a Web Part

When developing a web part (whether in WSS 3.0 or in ASP.Net 2.0) it can be important that it appears differently if the user is in edit mode. The simplest way to do this is to test the WebPartManager's DisplayMode in the web part's Render or CreateChildControls method.

protected override void CreateChildControls()
{
  ...
  if (this.WebPartManager.DisplayMode ==
      WebPartManager.BrowseDisplayMode)
  {
    // normal view mode (the page is not in edit mode)
  }
  else if (this.WebPartManager.DisplayMode ==
      WebPartManager.DesignDisplayMode)
  {
    // the page is in edit mode.
    // web parts can be moved between WebPartZones
  }
  else if (this.WebPartManager.DisplayMode ==
      WebPartManager.EditDisplayMode)
  {
    // the page and the web parts contained in it are in edit mode,
    // allowing access to specific actions of each one

  }
}

In the above example I'm testing the WebPartManager's DisplayMode in the web part's CreateChildControls method. When developing for WSS, it is most common to place the configuration controls only in the DesignDisplayMode, which means that the Edit Page button was pressed.

Posted: Friday, June 22, 2007 5:29 AM by andrevala

Comments

No Comments

Anonymous comments are disabled