Page view counter

How to disable custom verbs in a particular zone???

Last post 10-26-2007 5:42 PM by vinz. 6 replies.

Sort Posts:

  • How to disable custom verbs in a particular zone???

    10-26-2007, 10:03 AM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 11,856
    • Points 75,137

    Hi All,

     I have ed a custom webpartzone with custom verbs, my problem is how do i disable verbs in a particular zone?

    Scenario:

    CustomZone1 with CustomVerb <-- ENABLE

    CustomZone2 with CustomVerb <-- ENABLE

    CustomZone3 with CustomVerb <--- HOW TO DISABLE?

    This mean than if i move a webparts in CustomZone3 then all CustomVerb in each webparts will be disabled. How do i achieved this?? Any help?

     

  • Re: How to disable custom verbs in a particular zone???

    10-26-2007, 10:34 AM
    Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
  • Re: How to disable custom verbs in a particular zone???

    10-26-2007, 11:23 AM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 11,856
    • Points 75,137

    Thanks for your reply, actually i already read about it but i think it has nothing to do with my problem now. Actually I have created custom zone with 4 custom verbs (move right,move left and so on ) like the my.msn.com where you can move webparts in different zones without drag and drop functionality. if a webpart is in the rightmost webpartszone position i want to disable the "move right" custom verb .My problem is  How can i disable it?

  • Re: How to disable custom verbs in a particular zone???

    10-26-2007, 11:57 AM

    The reason I pointed out that link to draw your attention to this..... quoting from the link

    The WebPartZoneBase class also contains a number of members for handling verbs in a zone. These members relate to the verbs that appear on the part controls in the zone. While zone-level verbs can be added to WebPartZoneBase zones, by default they do not have any. There is a set of standard verbs provided with the Web Parts control set for use with part controls, and developers can add custom verbs as well. Some important properties for working with verbs include properties that reference some of the standard verb objects, such as CloseVerb, ConnectVerb, DeleteVerb, and EditVerb, HelpVerb, and MinimizeVerb. The standard verbs appear on a verbs menu (typically presented in the UI as a drop-down menu) in the title bar of each control contained in a zone. There is also a VerbButtonType property that allows you to determine what type of clickable object represents a verb in the UI.

    Other key members for working with verbs include the OnCreateVerbs method, which is an event handler that can be overridden for custom handling of the verb creation process, and the CreateVerbs event.

    The WebPartZoneBase class contains a number of members for working with WebPart controls contained within a zone. The WebParts property references the collection of all WebPart (and other server) controls in the zone. Several methods correspond to the standard verbs or actions that a user can carry out on WebPart controls in a zone, such as CloseWebPart, ConnectWebPart, and EditWebPart.

    There are also a number of members in the WebPartZoneBase class that concern how the WebPart controls are laid out or arranged within the zone. The AllowLayoutChange property determines whether controls can be moved among zones or rearranged within a zone by users. The LayoutOrientation property allows you to determine whether the controls in a zone are arranged horizontally or vertically.

    Other methods in the WebPartZoneBase class provide you with detailed programmatic control over the rendering of the various areas of a zone. Many of these methods override the base methods inherited from the WebZone class, to customize the rendering for zones that contain WebPart controls. Important methods include Render, RenderBody, RenderDropCue, and RenderHeader.

     

     

    Now based on above you have several options, deal with it in  CreateVerbs method like so

    if !(ENDOFZONE)  ///CHECK either based on style or otherwise...

    {

        //CREATE MOVE RIGHT VERB

    }

    Or even in OnCreateVerb

    The other option is to change it based on making verbs as properties and set them based on conditions.... Here is an article for the same http://www.codeguru.com/csharp/sample_chapter/print.php/c13037__3/ ...look at this delegate

    WebPartVerb clearVerb = new WebPartVerb(
       "ClearVerb1",
       new WebPartEventHandler(ClearTime)
       );
    
    I can provide a simple solution, but since this is your first..i want you to read it...
    Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
  • Re: How to disable custom verbs in a particular zone???

    10-26-2007, 1:14 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 11,856
    • Points 75,137

     I got your point.. thanks for giving me directions. this is a good start to deal with... thanks a lot it makes a lot of sense

  • Re: How to disable custom verbs in a particular zone???

    10-26-2007, 1:45 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 11,856
    • Points 75,137

     Hi,

    Currently i able to move webparts  from left or right zone but  when i set the enable property to false. it wont work at all

    this is my code snippet

    namespace AspNet.CustomWebparts.CS.Controls
    {

        [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]   
        [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
           
      
            public class ZoneWithAddedVerb : WebPartZone
            {         

                protected override void OnCreateVerbs(WebPartVerbsEventArgs e)
                {
                  
                    List<WebPartVerb> newVerbs = new List<WebPartVerb>();
                    newVerbs.Add(new MoveToRight(GoRight));
                    newVerbs.Add(new MoveToLeft(GoLeft));
                    e.Verbs = new WebPartVerbCollection(e.Verbs, newVerbs);
                    base.OnCreateVerbs(e);            
                   
                }

                        void GoRight(object sender, WebPartEventArgs e)
                        {

                           int wpindex = (int)e.WebPart.ZoneIndex;//get the webpart index within the zone

                           string zname = (string)e.WebPart.Zone.ID; //gets the zone name
                           string del = "b";
                           string[] temp = zname.Split(del.ToCharArray());//splits the name to get the last numeric value
                           int zid = int.Parse(temp[1].ToString());// get the numeric value of a zone


                           WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page);//gets the available webpartmanager on the page
                           if (zid < 4)
                           {
                               if (zid == 3)
                               {
                                   ((System.Web.UI.WebControls.WebParts.WebPartVerb)(sender)).Enabled = false;<---------- CODE TO VALIDATE MOVE TO RIGHT VERB WONT WORK

                               }
                               GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; //get the current control being move within the zone
                               wpm1.MoveWebPart(part, wpm1.Zones[zid], wpindex);//move the webpart to another or within a zone * e.WebPart.Zone.WebParts.Count
                           }  


                        void GoLeft(object sender, WebPartEventArgs e)
                        {

                            int wpindex = (int)e.WebPart.ZoneIndex;//get the webpart index location within the zone
                            string zname = (string)e.WebPart.Zone.ID; //gets the zone name
                            string del = "b";
                            string[] temp = zname.Split(del.ToCharArray());//splits the name to get the last numeric value
                            int zid = int.Parse(temp[1].ToString());// get the numeric value of a zone

                            WebPartManager wpm1 = WebPartManager.GetCurrentWebPartManager(Page);//gets the available webpartmanager on the page
                            if (zid != 1)
                            {

                                GenericWebPart part = (GenericWebPart)wpm1.Zones[zid - 1].WebParts[wpindex]; //get the current control being move within the zone
                                wpm1.MoveWebPart(part, wpm1.Zones[zid-2], wpindex);//move the webpart to another or within a zone
                            }

                            else

                            {

                                    ((System.Web.UI.WebControls.WebParts.WebPartVerb)(sender)).Enabled = false; <---------- CODE TO VALIDATE MOVE TO LEFT VERB WONT WORK

                            }
                        }

     

    //CODE FOR CREATE CUSTOM VERBS 

        [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]

          internal class MoveToRight : WebPartVerb
            {
                private const String _copyWebPartImageUrl = "~/icons/webpart verbs/right.gif";
                internal MoveToRight(WebPartEventHandler serverClickHandler)
                    :
                   
                base("MyVerbRight", 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 _copyWebPartImageUrl;
     
                    }
                    set { ; }
                }

            }

    internal class MoveToLeft : WebPartVerb
        {
            private const String _copyWebPartImageUrl = "~/icons/webpart verbs/left.gif";

            internal MoveToLeft(WebPartEventHandler serverClickHandler):
               

               base("MyVerbLeft", 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 _copyWebPartImageUrl; }
                set { ; }
            }
        }

  • Re: How to disable custom verbs in a particular zone???

    10-26-2007, 5:42 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 11,856
    • Points 75,137

    Got the solution already and it works great here.. I just added this validation on the OnCreateVerb below

    protected override void OnCreateVerbs(WebPartVerbsEventArgs e)
                {

                        string CustomZone_Id = this.ID;
                        List<WebPartVerb> newVerbs = new List<WebPartVerb>();

                        if (CustomZone_Id == "ZoneWithAddedVerb3") <-------- // VALIDATE IF THE WEBPART RESIDES IN THE RIGHTMOST ZONE THE CUSTOM MOVE RIGHT VERB WILL DISABLED
                            { newVerbs.Add(new Right(GoRight)); }
                            else
                            { newVerbs.Add(new MoveToRight(GoRight)); }

                            newVerbs.Add(new MoveToLeft(GoLeft));


                        e.Verbs = new WebPartVerbCollection(e.Verbs, newVerbs);
                        base.OnCreateVerbs(e);                  
                }

     
     

Page 1 of 1 (7 items)