Using WebPartZone : WebPartZone « WebPart « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » WebPart » WebPartZone 




Using WebPartZone

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

<!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>Default Web Parts Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:WebPartManager ID="WebPartManager1" runat="server">
        </asp:WebPartManager>
        Mode: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Selected="True">Browse</asp:ListItem>
            <asp:ListItem>Design</asp:ListItem>
            <asp:ListItem>Catalog</asp:ListItem>
        </asp:DropDownList>
    </div>
        <asp:WebPartZone ID="WebPartZone1" runat="server" BorderColor="Yellow" Font-Names="Verdana"
            Padding="6">
            <PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
            <MenuLabelHoverStyle ForeColor="#E2DED6" />
            <EmptyZoneTextStyle Font-Size="0.8em" />
            <MenuLabelStyle ForeColor="White" />
            <MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="Yellow" BorderStyle="Solid"
                BorderWidth="1px" ForeColor="Red" />
            <HeaderStyle Font-Size="0.7em" ForeColor="Yellow" HorizontalAlign="Center" />
            <ZoneTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            </ZoneTemplate>
            <MenuVerbStyle BorderColor="#5D7B9D" 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="#5D7B9D" BorderColor="Yellow" BorderWidth="1px" Font-Names="Verdana"
                Font-Size="0.6em" />
            <PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
        </asp:WebPartZone>
        &nbsp;&nbsp;
        <asp:WebPartZone ID="WebPartZone2" runat="server" BorderColor="Yellow" Font-Names="Verdana"
            Padding="6">
            <PartChromeStyle BackColor="#F7F6F3" BorderColor="#E2DED6" Font-Names="Verdana" ForeColor="White" />
            <MenuLabelHoverStyle ForeColor="#E2DED6" />
            <EmptyZoneTextStyle Font-Size="0.8em" />
            <MenuLabelStyle ForeColor="White" />
            <MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="Yellow" BorderStyle="Solid"
                BorderWidth="1px" ForeColor="Red" />
            <HeaderStyle Font-Size="0.7em" ForeColor="Yellow" HorizontalAlign="Center" />
            <MenuVerbStyle BorderColor="#5D7B9D" 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="#5D7B9D" BorderColor="Yellow" BorderWidth="1px" Font-Names="Verdana"
                Font-Size="0.6em" />
            <PartTitleStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.8em" ForeColor="White" />
        </asp:WebPartZone>
        <asp:CatalogZone ID="CatalogZone1" runat="server">
            <ZoneTemplate>
                <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
            </ZoneTemplate>
        </asp:CatalogZone>
        &nbsp;
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
    if (this.IsPostBack == false)
    {
      this.WebPartZone1.Visible = true;
      this.WebPartZone2.Visible = true;
    }
    }
  protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
    if (DropDownList1.SelectedValue.ToLower() == "browse")
    {
      WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
    }
    else if (DropDownList1.SelectedValue.ToLower()=="design" )
    {
      WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
    }
    else
    {
      WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
    }
  }
}

 














Related examples in the same category
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.