Web part with WebPartManager : WebPartManager « WebPart « ASP.Net






Web part with WebPartManager


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="WebPartsSample" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Web Parts Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:WebPartManager ID="WebPartManager1" runat="server">
        </asp:WebPartManager>
        <asp:RadioButtonList ID="RadioButtonList1" 
                             runat="server" 
                             AutoPostBack="True" 
                             OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
                             RepeatColumns="3">
            <asp:ListItem Selected="True">Browse</asp:ListItem>
            <asp:ListItem>Edit</asp:ListItem>
            <asp:ListItem>Catalog</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        <table>
            <tr>
                <td>
                    <asp:WebPartZone ID="WebPartZone1" runat="server">
                        <ZoneTemplate>
                            <asp:Calendar ID="Calendar1" 
                                          runat="server" 
                                          DayNameFormat="Shortest" 
                                          Height="180px" 
                                          Width="200px">
                                <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
                                <SelectorStyle BackColor="Navy" />
                                <WeekendDayStyle BackColor="#FFFFCC" />
                                <OtherMonthDayStyle ForeColor="Gray" />
                                <TodayDayStyle BackColor="Navy" ForeColor="Black" />
                                <NextPrevStyle VerticalAlign="Bottom" />
                                <DayHeaderStyle BackColor="Navy" Font-Bold="True" Font-Size="7pt" />
                                <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
                            </asp:Calendar>
                        </ZoneTemplate>
                    </asp:WebPartZone>
                </td>
                <td>
                    <asp:WebPartZone ID="WebPartZone2" 
                                     runat="server" 
                                     BorderColor="Navy" 
                                     Font-Names="Verdana"
                                     Padding="6">
                        <PartChromeStyle BackColor="#EFF3FB" BorderColor="#D1DDF1" Font-Names="Verdana" ForeColor="Red" />
                        <MenuLabelHoverStyle ForeColor="#D1DDF1" />
                        <EmptyZoneTextStyle Font-Size="0.8em" />
                        <MenuLabelStyle ForeColor="White" />
                        <MenuVerbHoverStyle BackColor="#EFF3FB" 
                                            BorderColor="Navy" 
                                            BorderStyle="Solid"
                                            BorderWidth="1px" 
                                            ForeColor="Red" />
                        <HeaderStyle Font-Size="0.7em" 
                                     ForeColor="Navy" 
                                     HorizontalAlign="Center" />
                        <ZoneTemplate>
                            <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                                <asp:ListItem>Red</asp:ListItem>
                                <asp:ListItem>Green</asp:ListItem>
                                <asp:ListItem>Blue</asp:ListItem>
                            </asp:CheckBoxList>
                        </ZoneTemplate>
                        <MenuVerbStyle BorderColor="#507CD1" 
                                       BorderStyle="Solid" 
                                       BorderWidth="1px" 
                                       ForeColor="White" />
                        <PartStyle Font-Size="0.8em" ForeColor="Red" />
                        <TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
                        <MenuPopupStyle BackColor="#507CD1" 
                                        BorderColor="Navy" 
                                        BorderWidth="1px" 
                                        Font-Names="Verdana"
                                        Font-Size="0.6em" />
                        <PartTitleStyle BackColor="#507CD1" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
                    </asp:WebPartZone>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:WebPartZone ID="WebPartZone3" runat="server" BorderColor="Navy" Font-Names="Verdana"
                        Padding="6">
                        <PartChromeStyle BackColor="#EFF3FB" BorderColor="#D1DDF1" Font-Names="Verdana" ForeColor="Red" />
                        <MenuLabelHoverStyle ForeColor="#D1DDF1" />
                        <EmptyZoneTextStyle Font-Size="0.8em" />
                        <MenuLabelStyle ForeColor="White" />
                        <MenuVerbHoverStyle BackColor="#EFF3FB" 
                                            BorderStyle="Solid"
                                            BorderWidth="1px" 
                                            ForeColor="Red" />
                        <HeaderStyle Font-Size="0.7em" ForeColor="Navy" HorizontalAlign="Center" />
                        <ZoneTemplate>
                            <asp:BulletedList ID="BulletedList1" runat="server">
                                <asp:ListItem>List</asp:ListItem>
                                <asp:ListItem>Of</asp:ListItem>
                                <asp:ListItem>Things</asp:ListItem>
                            </asp:BulletedList>
                        </ZoneTemplate>
                        <MenuVerbStyle BorderColor="#507CD1" 
                                       BorderStyle="Solid" 
                                       BorderWidth="1px" 
                                       ForeColor="White" />
                        <PartStyle Font-Size="0.8em" ForeColor="Red" />
                        <TitleBarVerbStyle Font-Size="0.6em" 
                                           Font-Underline="False" 
                                           ForeColor="White" />
                        <MenuPopupStyle BackColor="#507CD1" 
                                        BorderColor="Navy" 
                                        BorderWidth="1px" 
                                        Font-Names="Verdana"
                                        Font-Size="0.6em" />
                        <PartTitleStyle BackColor="#507CD1" 
                                        Font-Bold="True" 
                                        Font-Size="0.8em" 
                                        ForeColor="White" />
                    </asp:WebPartZone>
                </td>
                <td>
                    <asp:WebPartZone ID="WebPartZone4" 
                                     runat="server" 
                                     BorderColor="Navy" 
                                     Font-Names="Verdana"
                                     Padding="6">
                        <PartChromeStyle BackColor="#EFF3FB" 
                                         BorderColor="#D1DDF1" 
                                         Font-Names="Verdana" 
                                         ForeColor="Red" />
                        <MenuLabelHoverStyle ForeColor="#D1DDF1" />
                        <EmptyZoneTextStyle Font-Size="0.8em" />
                        <MenuLabelStyle ForeColor="White" />
                        <MenuVerbHoverStyle BackColor="#EFF3FB" 
                                            BorderColor="Navy" 
                                            BorderStyle="Solid"
                                            BorderWidth="1px" 
                                            ForeColor="Red" />
                        <HeaderStyle Font-Size="0.7em" 
                                     ForeColor="Navy" 
                                     HorizontalAlign="Center" />
                        <ZoneTemplate>
                            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                        </ZoneTemplate>
                        <MenuVerbStyle BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
                        <PartStyle Font-Size="0.8em" ForeColor="Red" />
                        <TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="White" />
                        <MenuPopupStyle BackColor="#507CD1" 
                                        BorderColor="Navy" 
                                        BorderWidth="1px" 
                                        Font-Names="Verdana"
                                        Font-Size="0.6em" />
                        <PartTitleStyle BackColor="#507CD1" 
                                        Font-Bold="True" 
                                        Font-Size="0.8em" ForeColor="White" />
                    </asp:WebPartZone>
                </td>
            </tr>
        </table>
    
    </div>
        <asp:CatalogZone ID="CatalogZone1" runat="server">
            <ZoneTemplate>
                <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
            </ZoneTemplate>
        </asp:CatalogZone>
        <asp:EditorZone ID="EditorZone1" runat="server">
        </asp:EditorZone>
    </form>
</body>
</html>


File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebPartsSample : System.Web.UI.Page
{

  protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
  {
    if (this.RadioButtonList1.SelectedValue.ToLower() == "browse")
    {
      this.WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
    }
    else if (this.RadioButtonList1.SelectedValue.ToLower() == "edit")
    {
      this.WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode;
    }
    else
    {
      this.WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
    }
  }
}

 








Related examples in the same category

1.Display Mode Menu