Frequently, need for switching between different modes in WebPart page programmatically is felt. For this we have used using various SharePoint JavaScript functions like MSOTlPn_ShowToolPaneWrapper, MSOLayout_ToggleLayoutMode etc. have been used in the past.New approach for the switching between WebPart modes would be to use WebPartManager DisplayModes collection and setting DisplayMode.Below attached sample webpart code, achieves the same. When you load the page in a browser, Display Mode drop-down list control is populated with display modes and is used to switch to different display modes. To edit controls, select Edit in the drop-down list control. When you are finished, select Browse in the Display Mode drop-down list control to return the page to a normal view. To add controls to the page, switch to catalog mode.
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace SPUtil
{
[Guid("68e96c2c-c788-4cf3-834a-9a7ec1ba0d9c")]
public class EditModeSwitchWebPart : System.Web.UI.WebControls.WebParts.WebPart
{
DropDownList dropdownDisplayMode;
protected override void CreateChildControls()
{
base.CreateChildControls();
dropdownDisplayMode = new DropDownList();
dropdownDisplayMode.AutoPostBack = true;
dropdownDisplayMode.SelectedIndexChanged += new EventHandler(dropdownDisplayMode_SelectedIndexChanged);
foreach (WebPartDisplayMode wpDisplayMode in WebPartManager.DisplayModes)
{
WebPartDisplayMode enabledWpDisplayMode = WebPartManager.SupportedDisplayModes[wpDisplayMode.Name];
if (enabledWpDisplayMode != null)
dropdownDisplayMode.Items.Add(enabledWpDisplayMode.Name);
}
Controls.Add(dropdownDisplayMode);
}
void dropdownDisplayMode_SelectedIndexChanged(object sender, EventArgs e)
{
if(this.dropdownDisplayMode.SelectedItem != null)
this.WebPartManager.DisplayMode = WebPartManager.DisplayModes[dropdownDisplayMode.SelectedValue];
}
}
}
Through this blog, it is my effort to share experiences with the community and make the journey enjoyable.
Search This Blog
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway. All posts are provided "AS IS" with no warranties, and confers no rights. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time snapshot you should not consider out of date posts to reflect my current thoughts and opinions.
Categories
- SharePoint ( 8 )
- #spfx ( 5 )
- #spfx-tooling ( 5 )
- #spfx-webparts ( 5 )
- SharePoint Framework ( 5 )
- Ionic ( 3 )
- Application Page ( 2 )
- Cordova ( 2 )
- Ionic 2 ( 2 )
- Mobile ( 2 )
- SharePoint 2010 ( 2 )
- SharePoint 2013 ( 2 )
- Software Methodologies ( 2 )
- WebPart ( 2 )
- Agile ( 1 )
- Auditing ( 1 )
- Best Practises ( 1 )
- Business Entities ( 1 )
- Custom Actions ( 1 )
- Enterprise Web 2.0 ( 1 )
- Feature ( 1 )
- List Rendering Template ( 1 )
- Office 365 ( 1 )
- People Picker ( 1 )
- SPD 2010 ( 1 )
- SaveButton ( 1 )
- SharePoint Designer 2010 ( 1 )
- SharePoint Event ( 1 )
- SharePoint India ( 1 )
- SharePoint Saturday ( 1 )
Popular Posts
-
Oracle Universal Content Management Integration with SharePoint using Web Parts WebParts to use Oracle ECM as backend and SharePoint as fro...
-
Introduction - SharePoint DataSheet Page is used for editing lists in multiple record grid format. DataSheet view uses ListNet control, w...
-
Introduction - Windows SharePoint Services 3.0 introduces built-in audit logging you can enable and configure at the scope of a site colle...
-
Overview - SharePoint Upload.aspx page is used for uploading documents from the document libraries and other lists. Upload.aspx is called,...
-
SharePoint 2013 provides client side people picker. Following snippet helps to set the form value using JQuery and validate the user. B...
-
While starting on design of SharePoint Custom applications, one of the dilemma which comes - Whether to use SharePoint lists as DataStore or...
-
Join SharePoint architects, developers, and other professionals from India that work with Microsoft Office SharePoint Server 2010 and 2007 f...
-
On creating new Ionic 2 project templates with Visual Studio 2015, build is failing with the Error (DEP10402) : Could not locate the star...
-
Microsoft Office SharePoint Designer is a free WYSIWYG HTML editor and web design program from Microsoft for SharePoint and other websites ...
-
' The load balancer is not provisioned. Verify the load balancer was provisioned successfully before retrieving endpoint addresses'...
0 comments :
Post a Comment