using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Security.Permissions; using System.Collections.Generic; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// Custom WebPartZone with custom verbs /// namespace Samples.CustomWebpartZone.CS.Controls { [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] //Inherits the webpartzone class public class CustomZoneWithNewVerb : WebPartZone { //Overrides the OnCreateVerbs Methods protected override void OnCreateVerbs(WebPartVerbsEventArgs e) { //NOTE:MoveToLeft and MoveToRight are the name of methods where the custom verbs are created. While the parameter RightVerb and LeftVerb are the event handlers for those verbs. List<WebPartVerb> addNewVerbs = new List<WebPartVerb>(); addNewVerbs.Add(new MoveToRight(RightVerb)); addNewVerbs.Add(new MoveToLeft(LeftVerb)); e.Verbs = new WebPartVerbCollection(e.Verbs, addNewVerbs); base.OnCreateVerbs(e); } void RightVerb(object sender, WebPartEventArgs e) { //gets the total number of webparts that is present in a particular zone int wpcount = (int)e.WebPart.Zone.WebParts.Count; //get the webpart index within the zone int wpindex = (int)e.WebPart.ZoneIndex; //gets the zone name string zname = (string)e.WebPart.Zone.ID; string del = "b"; //splits the id name “CustomZoneWithNewVerb1” to get the last numeric value string[] temp = zname.Split(del.ToCharArray()); // get the numeric value of a zone “1” int zoneid = int.Parse(temp[1].ToString()); //gets the available webpartmanager on the page WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page); if (zid < 3) //assume that you have 3 zones in your page { //get the current control being move within the zone GenericWebPart part = (GenericWebPart)wpm1.Zones[zoneid - 1].WebParts[wpindex]; //move the webpart to another or within a zone wpm1.MoveWebPart(part, wpm1.Zones[zoneid], wpindex); } } void LeftVerb(object sender, WebPartEventArgs e) { int wpcount = (int)e.WebPart.Zone.WebParts.Count; int wpindex = (int)e.WebPart.ZoneIndex; string zname = (string)e.WebPart.Zone.ID; string del = "b"; string[] temp = zname.Split(del.ToCharArray()); int zoneid = int.Parse(temp[1].ToString()); WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page); if (zid != 1) { GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; wpm1.MoveWebPart(part, wpm1.Zones[zid-2], wpindex); } } [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] //A fucntion where custom Move Right verbs are created //Inherits WebpartVerb class to create custom verbs internal class MoveToRight : WebPartVerb { private const String _WebPartImageUrl = "~/image/right.gif"; internal MoveToRight(WebPartEventHandler serverClickHandler) : base("GotoRight", serverClickHandler) { } public override string Text { get { return "Move Right"; } set { ;} } public override string Description { get { return "Allows you to move webparts to the right zone "; } set { ; } } public override bool Enabled { get { return base.Enabled; } set { base.Enabled = value; } } public override string ImageUrl { get { return _WebPartImageUrl; } set { ; } } } //A fucntion where custom Move Left verbs are created //Inherits WebpartVerb class to create custom verbs internal class MoveToLeft : WebPartVerb { private const String _WebPartImageUrl = "~/image/left.gif"; internal MoveToLeft(WebPartEventHandler serverClickHandler): base("GotoLeft", serverClickHandler) { } public override string Text { get { return "Move Left"; } set { ;} } public override string Description { get { return "Allows you to move webparts to the left zone "; } set { ; } } public override bool Enabled { get { return base.Enabled; } set { base.Enabled = value; } } public override string ImageUrl { get { return _WebPartImageUrl; } set { ; } } } { get { return base.Enabled; } set { base.Enabled = value; } } public override string ImageUrl { get { return _copyWebPartImageUrl; } set { ; } } } |