Web Parts in ASP.Net

Objective


To develop a web application using WebParts in asp.net

  • Design: Design the form with one WebPartManager, one DropDownList, two or more WebPartZone controls, one CatalogZone control, one EditorZone control.
  • Create a few web user controls and place one in WebPartZone1, another in WebPartZone2
  • Now place DeclarativeCatalogPart control in CatalogZone1
  • select DeclarativeCatalogPart1->click on '>' button, select 'Edit Templates'and place all the created webusercontrols in it-> select 'End TemplateEditng'.
  • Place LayoutEditorPart, AppearanceEditorPart, PropertyGridEditorPart, BehaviourEditorPart in EditorZone1
  • Select DropDownList1-> Edit Items-> Add Browse,Design,Catalog,Design and also check EnableAutoPostBack option

Code

using System;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class _Default : System.Web.UI.Page
{
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedIndex)
        {
            case 0:
                WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
                break;
            case 1:
                WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
                break;
            case 2:
                WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
                break;
            case 3:
                WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode;
                break;
            default:
                break;
        }
    }
}


Similar Articles