ToolBox WepParts Control WebPartZone

WebPartZone Web Server Control

in ASP.NET environment,This article describes you how to work with WebPartZone Web Control.here,The WebPartZone control can act as the primary control of the Web Parts control set for the hosting WebPart controls on a Web page, and provides a common UI for its controls.The major mechanism of the WebPartZone control is to contain WebPart controls that form the main UI of Web Parts applications. A WebPartZone control can be declared in persistence format on a Web page, enabling developers to use it as a template and to add other server controls within the <asp:WebPartZone> element.

WebPartZone UI Elements

Normally, user interface elements can derive from the base class WebZone, . These common UI elements are known collectively as chrome and consist of the peripheral UI elements on all the controls, such as the border, title, header and footer, style characteristics.

The following code snippets explains you the use of the WebPartZone control in a Web Parts page.

in .aspx page,

 <%@ Register TagPrefix="uc" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="MyWebPartZoneCS" %>

<html  >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form2" runat="server">
    <div>
      <asp:WebPartManager ID="WebPartManager1" runat="server" />
      <uc:MyWebPartZone ID="MyWebPartZone1" runat="server">
        <VerbStyle Font-Italic="true" />
        <PartChromeStyle BackColor="lightblue" />
        <PartStyle BackColor="gray" />
        <PartTitleStyle Font-Bold="true" />
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </cc1:MyWebPartZone>
    </div>
    </form>
</body>
</html>
        
 
Related Links

Posted by: Admin
Posted on: 9/17/2009 at 5:15 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (26) | Post RSSRSS comment feed

ToolBox WepParts Control WebPartManager

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

Posted by: Admin
Posted on: 9/17/2009 at 5:13 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (67) | Post RSSRSS comment feed

ToolBox WepParts Control ProxyWebPartManager

ProxyWebPartManager Web Server Control

in ASP.NET environment,This article describes you how to work with ProxyWebPartManager Web Control.The ProxyWebPartManager control can create static connections in a content page when a WebPartManager control has been declared in the content page's associated master page.

Moreover, The WebPartManager control is used by a page that manages all Web Parts controls on the page. When a Web Parts application uses master pages, it is common to place the WebPartManager control in the master page. When content pages are merged with the master page at run time, the single WebPartManager control can manage Web Parts controls on all the content pages.

<staticconnections> element can declare a static connection and that required the child element <asp:webpartconnection>. when you use master pages and put the WebPartManager control in the master page, you cannot create a <asp:webpartmanager> element in a content page; only one WebPartManager control is permitted. The solution is to use a ProxyWebPartManager control on the content page, which takes the place of the WebPartManager control.

The ProxyWebPartManager's connections are added to the StaticConnections collection of the WebPartManager control in the Runtime and treated like any other connection.

ProxyWebPartManager Vs WebManagerControl

  • The ProxyWebPartManager control is used only when you have created a WebPartManager control in a master page and you want to declare static connections in the content page.
  • The ProxyWebPartManager control therefore has more limited functionality than the WebPartManager control.
  • Although the ProxyWebPartManager control acts as a proxy to contain static connections for the WebPartManager control in content pages, it does not inherit from the WebPartManager control.

The following code snippets explains you the ProxyWebPartManager to declare static connections on content pages in an application that uses master pages

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,

<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <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>
</div>
                    
 
Related Links

Posted by: Admin
Posted on: 9/17/2009 at 5:12 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (41) | Post RSSRSS comment feed

ToolBox WepParts Control PropertyGridEditorPart

PropertyGridEditorPart Web Server Control

in ASP.NET environment,This article describes you how to work with PropertyGridEditorPart Web Control.The mechanism of PropertyGridEditorPart can provide an editor control that enables users to edit Custom properties on web Part controls and Custom properties on server controls.

The users can edit custom properties sets other than the EditorPart controls, such as the AppearanceEditorPart and BehaviorEditorPart controls, that edit only existing, By using the PropertyGridEditorPart control.

The Web Parts control set contains the following two features:

  • They are helper controls that enable end users to personalize controls on a Web Parts page.
  • They are visible only in certain display modes.

The following properties are respect to the related controls are as follows:

  • String - TextBox
  • Int, Float, Unit - TextBox
  • Boolean - CheckBox
  • Enum - DropDownList
  • DateTime - TextBox
Properties of PropertyGridEditorPart
  • Title property - allows the user to gets or sets the title for a layout control.
  • Display property -Describes the visiblity of the PropertyGridEditorPart control. The PropertyGridEditorPart control is always visible when the page is in edit mode,
Methods of LayoutEditorPart
  • ApplyChanges- Saves the values from a PropertyGridEditorPart control to the corresponding properties. return true when saving is succeed, otherwise false.
  • SyncChanges-Retrieves the property values from a WebPart control and assigns them to the associated PropertyGridEditorPart control.

the following code snippets demonstrates how to work with the PropertyGridEditorPart Control

in .aspx.cs page,

protected void Page_Load(object sender, EventArgs e)
  {
    btn1.Visible = false;
    txt1.Visible = false;
  }

  private static String editControlTitle;
  
  protected void btn1_Click(object sender, EventArgs e)
  {
    editControlTitle = Server.HtmlEncode(txt1.Text);
    pgep1.Title = editControlTitle;
  }

  protected void pgep1_Init(object sender, EventArgs e)
  {
    if (editControlTitle != null)
      pgep1.Title = editControlTitle;
  }  

  protected void pgep1_PreRender(object sender,
    EventArgs e)
  {
    btn1.Visible = true;
    txt1.Visible = true;
  }    

in .aspx page,

   
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="UserInfoWebPartCS" %>
  
<html>
  <head id="Head1" runat="server">
    <title>
      User Information WebPart with EditorPart
    </title>
  </head>
  <body>
    <form id="form2" runat="server">
      <asp:webpartmanager id="wp1" runat="server"  />
      <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server" >
        <PartTitleStyle BorderWidth=1 
          Font-Names="Verdana, Arial"
          Font-Size="110%"
          BackColor="LightBlue" />
        <zonetemplate>
          <aspSample:UserInfoWebPart 
            runat="server"   
            id="userinfo" 
            title = "User Information WebPart"
            BackColor="Beige" />          
        </zonetemplate>
      </asp:webpartzone> 
      <div>
      <hr />
      <asp:Button ID="btn1" runat="server" 
        Text="Update EditorPart Title" 
        OnClick="btn1_Click" />
      <asp:TextBox ID="txt1" runat="server"></asp:TextBox>
      </div>
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:PropertyGridEditorPart ID="pgep1" 
            runat="server" 
            Title="Edit Custom Properties"
            OnPreRender="pgep1_PreRender" 
            OnInit="pgep1_Init" />   
        </ZoneTemplate>
      </asp:EditorZone>
    </form>
  </body>
</html>    
 
Related Links

Posted by: Admin
Posted on: 9/17/2009 at 5:10 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (41) | Post RSSRSS comment feed

ToolBox WepParts Control PageCatalogPart

PageCatalogPart Web Server Control

in ASP.NET environment,This article describes you how to work with PageCatalogPart Web Control.The primary function of the DeclarativeCatalogPart control is that provides a catalog that holds references to all WebPart controls which a user has closed on a single Web Parts page.during a page is running, The user interface of the PageCatalogPart control enables the user to add the closed controls back to the page.

Here, This control only at visible stage when a page is in catalog display mode. when an user needs with closing and reopening controls, then Add a PageCatalogPart control to your page.

A Closed Control

A closed control has several attributes such as:

  • It does not visible on the page.
  • It does not rendered on the page.
  • It does not participate in page life-cycle phases.

The following elements must need to include with a page

  • <asp:catalogzone> element must be included, and a child <zonetemplate> element must be added to it
  • <asp:PageCatalogPart> element must be added as a child of the <zonetemplate> element.

the following code snippets demonstrates how to work with the PageCatalogPart Control

in .aspx page,

<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="UserInfoWebPartCS" %>

  
<html>
  <head id="Head1" runat="server">
    <title>
      PageCatalogPart Example
    </title>
  </head>
  <body>
    <form id="form2" runat="server">
      <asp:webpartmanager id="wp1" runat="server"  />
      <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server" >
        <PartTitleStyle BorderWidth=1 
          Font-Names="Verdana, Arial"
          Font-Size="110%"
          BackColor="LightBlue" />
        <zonetemplate>
          <asp:BulletedList ID="BulletedList1" 
            Runat="server"
            DisplayMode="HyperLink"
            Title="Favorites">
            <asp:ListItem Value="http://www.gmail.com">
              Gmail
            </asp:ListItem>
          </asp:BulletedList>
        </zonetemplate>
      </asp:webpartzone> 
      <asp:CatalogZone ID="CatalogZone1" runat="server">
        <ZoneTemplate>
          <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" 
            Title="My Page Catalog" 
            ChromeType="Titleonly" />
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1"  
            runat="server" 
            Description="Contains a user control with Web Parts and 
              an ASP.NET Calendar control.">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" 
           Description="ASP.NET Calendar control used as a personal calendar." />
              <aspSample:UserInfoWebPart 
                runat="server"   
                id="userinfo1" 
                title = "User Information WebPart"
                Description ="Contains custom, editable user information 
                  for display on a page." />
              <aspSample:TextDisplayWebPart 
                runat="server"   
                id="TextDisplayWebPart1" 
                title = "Text Display WebPart" 
          Description="Contains a label that users can dynamically update." />
            </WebPartsTemplate>              
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
    </form>
  </body>
</html>
        
 
Related Links

Posted by: Admin
Posted on: 9/17/2009 at 5:06 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (38) | Post RSSRSS comment feed