- WebPartManager Web Server Control
in ASP.NET environment,This article describes you how to work with WebPartManager
Web Control.In DOT.Net environment, The WebPartManager control can serve as the
hub or control center of a Web Parts application.In every page, There must be one--and
only one--WebPartManager control instance that uses Web Parts controls. But an authenticted
user only access the most aspects of Web Parts applications, the WebPartManager
control works only with authenticated users.
Moreover, server controls only can working with its functionality that reside within
Web Parts zones that inherit from the WebZone class. Server controls that reside
on a page outside of these zones can have very little Web Parts functionality or
interaction with the WebPartManager control.
WebPartManager's Tasks
- Tracking Web Parts controls -Keeps track of the many different kinds of controls
on a page that provide Web Parts features, including WebPart controls, connections,
zones, and others.
- Adding and removing Web Parts controls -Provides the methods for adding,
deleting, and closing WebPart controls on a page.
- Administering connections -Creates connections between controls, and monitors
the connections as well as the processes of adding and removing them.
- Personalizing controls and pages -Enables users to move controls to different
locations on a page, and launches the views in which users can edit the appearance,
properties, and behavior of controls. Maintains user-specific personalization settings
on each page.
- Toggling between different page views -Switches a page among different specialized
views of the page, so that users can carry out certain tasks such as changing page
layout or editing controls.
- Raising Web Parts life-cycle events -Defines, raises, and enables developers
to handle life-cycle events of Web Parts controls, such as when controls are being
added, moved, connected, or deleted.
- Enabling import and export of controls -Exports XML streams that contain
the state of the properties of WebPart controls, and allows users to import the
files for convenience in personalizing complex controls in other pages or sites.
WebPartManager's Fields Vs Display modes
- BrowseDisplayMode - The normal user view of a Web page; the default and most
common display mode.
- DesignDisplayMode -The view in which users can rearrange or delete controls
to change the page layout.
- EditDisplayMode - The view in which an editing user interface (UI) becomes
visible; users can edit the appearance, properties, and behavior of the controls
that are visible in the normal browse mode.
- CatalogDisplayMode -Enables users to move controls to different locations
on a page, and launches the views in which users can edit the appearance, properties,
and behavior of controls. Maintains user-specific personalization settings on each
page.
- ConnectDisplayMode -The view in which a connection UI becomes visible; users
can connect, manage, or disconnect connections between controls.
Events
- AuthorizeWebPart -Occurs just before a control is added to a page to verify
that it is authorized.
- ConnectionsActivated -Occurs after all the connections on a page have been
activated.
- ConnectionsActivating - Occurs just before the process of activating all
the connections on a page.
- DisplayModeChanged -Occurs after the current display mode of a page has changed.
- DisplayModeChanging -Occurs just before the process of changing a page's
display mode.
- AuthorizeWebPart -Occurs just before a control is added to a page to verify
that it is authorized.
- ConnectionsActivated -Occurs after all the connections on a page have been
activated.
- ConnectionsActivating - Occurs just before the process of activating all
the connections on a page.
- DisplayModeChanged -Occurs after the current display mode of a page has changed.
- DisplayModeChanging -Occurs just before the process of changing a page's
display mode.
- SelectedWebPartChanged -Occurs after the selection of a control has been
canceled.
- SelectedWebPartChanging -Occurs just before the process of canceling the
selection of a control.
- WebPartAdded -Occurs after a control has been added to a zone.
- WebPartAdding -Occurs just before the process of adding a control to a zone.
- WebPartClosed -Occurs after a control has been closed
- WebPartClosing -Occurs just before the process of closing a control.
- WebPartDeleted -Occurs after an instance of a dynamic control (one that was
created programmatically or added from a catalog) has been permanently deleted.
- WebPartDeleting -Occurs just before the process of deleting a dynamic control.
- WebPartMoved -Occurs after a control has moved within its zone or to another
zone.
- WebPartMoving -Occurs just before the process of moving a control.
- WebPartsConnected -Occurs after two controls selected for participation in
a connection have established the connection.
- WebPartsConnecting -Occurs just before the process of connecting two controls.
- WebPartsDisconnected -Occurs after two connected controls have been disconnected.
- WebPartsDisconnecting -Occurs just before the process of disconnecting two
controls.
The following code snippets explains you the WebPartManager control
in .aspx.cs page,
-
WebPartManager _manager;
void Page_Init(object sender, EventArgs e)
{
Page.InitComplete += new EventHandler(InitComplete);
}
void InitComplete(object sender, System.EventArgs e)
{
_manager = WebPartManager.GetCurrentWebPartManager(Page);
String browseModeName = WebPartManager.BrowseDisplayMode.Name;
foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
{
String modeName = mode.Name;
if (mode.IsEnabled(_manager))
{
ListItem item = new ListItem(modeName, modeName);
DisplayModeDropdown.Items.Add(item);
}
}
if (_manager.Personalization.CanEnterSharedScope)
{
Panel2.Visible = true;
if (_manager.Personalization.Scope == PersonalizationScope.User)
RadioButton1.Checked = true;
else
RadioButton2.Checked = true;
}
}
void DisplayModeDropdown_SelectedIndexChanged(object sender, EventArgs e)
{
String selectedMode = DisplayModeDropdown.SelectedValue;
WebPartDisplayMode mode = _manager.SupportedDisplayModes[selectedMode];
if (mode != null)
_manager.DisplayMode = mode;
}
void Page_PreRender(object sender, EventArgs e)
{
ListItemCollection items = DisplayModeDropdown.Items;
int selectedIndex =
items.IndexOf(items.FindByText(_manager.DisplayMode.Name));
DisplayModeDropdown.SelectedIndex = selectedIndex;
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
_manager.Personalization.ResetPersonalizationState();
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (_manager.Personalization.Scope == PersonalizationScope.Shared)
_manager.Personalization.ToggleScope();
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (_manager.Personalization.CanEnterSharedScope &&
_manager.Personalization.Scope == PersonalizationScope.User)
_manager.Personalization.ToggleScope();
}
-
in .aspx page,
-
<asp:Panel ID="Panel1" runat="server"
Borderwidth="1"
Width="230"
BackColor="lightgray"
Font-Names="Arial" >
<asp:Label ID="Label1" runat="server"
Text=" Display Mode"
Font-Bold="true"
Font-Size="8"
Width="120" />
<asp:DropDownList ID="DisplayModeDropdown" runat="server"
AutoPostBack="true"
Width="120"
OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
<asp:LinkButton ID="LinkButton1" runat="server"
Text="Reset User State"
ToolTip="Reset the current user's personalization data for the page."
Font-Size="8"
OnClick="LinkButton1_Click" />
<asp:Panel ID="Panel2" runat="server"
GroupingText="Personalization Scope"
Font-Bold="true"
Font-Size="8"
Visible="false" >
<asp:RadioButton ID="RadioButton1" runat="server"
Text="User"
AutoPostBack="true"
GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged" />
<asp:RadioButton ID="RadioButton2" runat="server"
Text="Shared"
AutoPostBack="true"
GroupName="Scope"
OnCheckedChanged="RadioButton2_CheckedChanged" />
</asp:Panel>
</asp:Panel>
-
- Related Links
-
733ddf65-5a76-4d38-a2d5-1a4b3d57b0e4|0|.0