Disable Verbs

Last post 03-09-2007 6:47 AM by Arjun Tiwari. 6 replies.

Sort Posts:

  • Disable Verbs

    08-11-2006, 11:31 AM
    • Member
      202 point Member
    • Zalihe
    • Member since 10-29-2003, 12:13 PM
    • Posts 105
        Hi,

    im very desperate here, my hair is comingo uti n chunks

    ive looked everyehere, and on these forums are as well but its not making sense,  im very dippy.

    any way the problem:

    I have a aspx page where the outline of my webpartmanger control sits.

    also on the paghe i have one webpartzone as well as an editor zone

    within this one webpartzone, i have a zone template and within this tempalte i have two usercontrols.
    one usercontrol is my webpart called useful links, and the other usercontrol is called my forums. 
    on my forums user control i have three panels doc formuns, ad forums and latestest posts formuns,  in my editor i have three checkboxes which when ticked can personal the page according to user.

    the problem is i do not want the Edit verb to appear on the useful links web part but it is.  How do i disable this?
    Maybe some of my code can make things clearer!

    <!--DEFAULT.aspx-->
                                <asp:WebPartZone ID="WPRightPanel" runat="server" HeaderText="Your Sections" EmptyZoneText="" EditVerb-Visible="true" CloseVerb-Text="X" MinimizeVerb-Text="Min" RestoreVerb-Text="Max" Padding="2" >
                                <MenuLabelStyle ForeColor="White" />
                                    <PartChromeStyle Font-Names="Verdana" ForeColor="White" />
                                    <MenuLabelHoverStyle ForeColor="#E2DED6" />
                                    <EmptyZoneTextStyle Font-Size="0.8em" />
                                    <MenuVerbHoverStyle BackColor="#F7F6F3" BorderColor="#CCCCCC" BorderStyle="Solid"
                                         BorderWidth="1px" ForeColor="#333333" />
                                    <HeaderStyle Font-Size="0.7em" ForeColor="#CCCCCC" HorizontalAlign="Center" />
                                    <MenuVerbStyle BorderColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
                                    <PartStyle Font-Size="0.8em" ForeColor="#333333" />
                                    <TitleBarVerbStyle Font-Size="0.6em" Font-Underline="False" ForeColor="Black" />
                                    <MenuPopupStyle BackColor="#5D7B9D" BorderColor="#CCCCCC" BorderWidth="1px" Font-Names="Verdana"
                                         Font-Size="0.6em" />
                                    <PartTitleStyle BackColor="Gray" Font-Bold="True" Font-Size="0.8em" ForeColor="Black" />
                                   
           
                                    <ZoneTemplate>
                                        <ucUsefulLinks:UsefulLinks ID="UsefulLinks1" runat="server" />
                                        <ucForums:Forums ID="Forumns1" runat="server" />
                                    </ZoneTemplate>
                                   
                                </asp:WebPartZone>
    <!--USefullinks.ascx-->
    <!--I tried the code in the prerender to see if it worked but nothing-->
    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Collections
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls


    Partial Class usefulLinks1
        Inherits System.Web.UI.UserControl
        Implements System.Web.UI.WebControls.WebParts.IWebPart

        Private _catalogImageUrl As String = String.Empty
        Private _description As String = String.Empty
        Private _subTitle As String = "[0]"
        Private _title As String = "Useful Links"

        Public Property CatalogIconImageUrl() As String Implements IWebPart.CatalogIconImageUrl
    ---

        Public Property Description() As String Implements IWebPart.Description
    ---

        Public ReadOnly Property Subtitle() As String Implements IWebPart.Subtitle
    ---

        Public Property Title() As String Implements IWebPart.Title
    ---
        Public Property TitleIconImageUrl() As String Implements IWebPart.TitleIconImageUrl
    ---
        Public Property TitleUrl() As String Implements IWebPart.TitleUrl
    ---
        Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
    ---
            Dim a As New System.Web.UI.WebControls.WebParts.WebPartZone
            a.EditVerb.Visible = False
            a.EditVerb.Enabled = False
            a.EditVerb.Text = ""
        End Sub    'OnPreRender
    End Class
    <!--Forumns.ascx-->
    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Collections
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls


    Partial Class forums1
        Inherits System.Web.UI.UserControl
        Implements System.Web.UI.WebControls.WebParts.IWebPart


        Protected _Forums As Boolean = True

        Protected _Posts As Boolean = True

        Protected _Ads As Boolean = True

        Private _catalogImageUrl As String = String.Empty
        Private _description As String = String.Empty
        Private _subTitle As String = "[0]"
        Private _title As String = "Forums"

        <Personalizable(PersonalizationScope.User), _
        WebBrowsable(), _
        WebDisplayName("Show Most Active Forums"), _
        WebDescription("Use this property to show/hide Most Active Forums")> _
        Public Property Forumns() As Boolean
    ---

        <Personalizable(PersonalizationScope.User), _
         WebBrowsable(), _
         WebDisplayName("Show Latest Posts"), _
         WebDescription("Use this property to show/hide Latest Posts")> _
        Public Property Posts() As Boolean
    ---

        <Personalizable(PersonalizationScope.User), _
         WebBrowsable(), _
         WebDisplayName("Show Personal Ad's"), _
         WebDescription("Use this property to show/hide Personal Ad's")> _
        Public Property Ads() As Boolean
    ---

        Public Property CatalogIconImageUrl() As String Implements IWebPart.CatalogIconImageUrl
    ---

        Public Property Description() As String Implements IWebPart.Description
    ---

        Public ReadOnly Property Subtitle() As String Implements IWebPart.Subtitle
    ---

        Public Property Title() As String Implements IWebPart.Title
     ---

        Public Property TitleIconImageUrl() As String Implements IWebPart.TitleIconImageUrl
    ---

        Public Property TitleUrl() As String Implements IWebPart.TitleUrl
    ---

        Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

            If Forumns = True Then
                pnlActiveForum.visible = True
            Else
                pnlActiveForum.visible = False
            End If

            If Posts = True Then
                pnlPost.visible = True
            Else
                pnlPost.visible = False
            End If

            If Ads = True Then
                pnlAd.visible = True
            Else
                pnlAd.visible = False
            End If

        End Sub    'OnPreRender
    End Class


    I do hope soemone can help me soon.

    Many thanxz in advance.

    Zal


  • Re: Disable Verbs

    08-14-2006, 7:20 AM
    • Member
      50 point Member
    • TeunD
    • Member since 02-26-2004, 5:00 AM
    • Posts 11

    This is typically one of those things that you can modify in a web server control that derives from System.Web.UI.WebParts.WebPart, but not from a UserControl.

    However, there are some possible workarounds:

    1. Implement the IWebActionable interface on the user controls code behind, return WebPartVerbCollection.Empty from it, but keep a reference. At PreRender, Disable the Edit Verb in the collection (which will be added by the Zone)

    2. Make a custom Zone, that recognizes your control and sets AllowEdit to false on the GenericWebPart wrapper

    3. Create a derived version of GenericWebPart that knows your control and create a custom webPartManager that reurns your wrapper instead of GenericWebPart from CreateWebPart()... nope, don't go there

    Advice: go for option 1.

  • Re: Disable Verbs

    08-14-2006, 11:05 AM
    • Member
      202 point Member
    • Zalihe
    • Member since 10-29-2003, 12:13 PM
    • Posts 105
    TeunD,
    Thanxz for your advise, i opted for option 1, but im stil stuck maybe you can further help me or maybe someone else out there can shed some light.

    I have disabled the edit-enable attribute from the webpart.
    i then went into my user control for foerumns and further added a readonly property called verbs as the webpartverbscollection and created a new verb and on the address of directed to a protected sub called EditClicks.  the problem now that i dont know exactly what to write in this sub.

    ive tried declareing an instance of the currentwebpartmanager and also declaring a varible set ot the editdisplaymode, but it doestn like the editMode.IsEnabled = true or my me.allowEdit = true

    HELP!!!!!!!!

    Zal

    I am trying very hard but these wb parts are not my thing, and the silly thing is i dsuggested them. :)
  • Re: Disable Verbs

    08-15-2006, 3:22 AM
    • Member
      50 point Member
    • TeunD
    • Member since 02-26-2004, 5:00 AM
    • Posts 11

    Zal,

    My apologies; thisturns out to be a lot harder than I initially thought.

    Setting the AllowEdit property of your part to False will prevent your part from being edited. You can just set the AllowEdit="False" property on your user control (VS.NET will put squigglies under it, but never mind). When you try to edit this part, the Edit zone will show, but will have no ToolParts loaded.

    This is not what you want: you want the verb to disappear. This turns out to be hard. Adding custom verbs to a part is easy, but removing them is not. The snippet below gives you an example of how to create acustom zone with acustom WebPartChrome that will make your verbs disabled where Editing is not allowed. Setting Visible to false will turn of the verb for other web parts in the same zone as well (or rather: all parts after the one with AllowEdit=false).

        public class HideEditZone : WebPartZone
        {
            public HideEditZone()
            {
    
            }
            protected override WebPartChrome CreateWebPartChrome()
            {
                return new MyChrome(this, this.WebPartManager);
            }
    
        }
        public class MyChrome : WebPartChrome
        {
            public MyChrome(WebPartZoneBase zone, WebPartManager mgr)
                :
                base(zone, mgr)
            { }
    
            protected override WebPartVerbCollection FilterWebPartVerbs(WebPartVerbCollection verbs, WebPart webPart)
            {
                WebPartVerbCollection defaultResult = base.FilterWebPartVerbs(verbs, webPart);
                foreach (WebPartVerb verb in defaultResult)
                {
                    if (verb == this.Zone.EditVerb)
                    {
                        verb.Enabled = webPart.AllowEdit;
                    }
                }
                return defaultResult;
            }
        }
    
    

  • Re: Disable Verbs

    08-15-2006, 12:01 PM
    • Member
      202 point Member
    • Zalihe
    • Member since 10-29-2003, 12:13 PM
    • Posts 105
    Hey TeunD,

    Thanxz for all your help.  ive come to the conclusion that i dont like sweb parts. :(

    havent really got time to customize my own classes.  so instead i have assigned the editable verb to all the web parts and they all are able to update the title of the web part in the menu section. 

    isnt wonderful, but is ok as a user can now call it my forums rather han forums.

    Zal

    if anyone reading this does manage to come up wityh some sort of soultion please post it, as im pretty sure that i am not the only person in the world who wishes to do this.

    "A man who asks a question is a fool for five minutes a man who never asks a question is a fool forever" - Chinese Proverb.


  • Re: Disable Verbs

    08-17-2006, 6:19 AM
    • Member
      50 point Member
    • TeunD
    • Member since 02-26-2004, 5:00 AM
    • Posts 11

    I did a short write-up of my attempts to achieve what Zal asked for (which sounded perfectly reasonable to me). I would really appreciate it when someone from the ASP.NET team (Mike?) could respond to this.

    Maybe I tried to solve this the wrong way, maybe there is a perfectly good reason for the observed behavior. I would really like to know.

     

    Thanks,

    Teun
    http://www.teuntostring.net/blog/

  • Re: Disable Verbs

    03-09-2007, 6:47 AM
    • Member
      2 point Member
    • Arjun Tiwari
    • Member since 03-09-2007, 6:40 AM
    • Posts 1

    Hi,

     

    I was just trying to find out some help but I didn't find anything to disable verbs.

    I did some rnd at my own end and got the result. Please find the below js that will solve the problem. Please let me know your input.

     

    <script type="text/javascript">

    function HideWebpartLevelMenu(ctrlID,showMenu)

    {

    /*

    Arjun Tiwari

    Hide edit or delete or any webpart menu that has not permission on

    LTrim, RTrim and trim function is required as supporting function to trim the spaces

    09032007

    */

    /*WebPart_wp786936923VerbsMenu

    syntax Prefix = WebPart_

    controls part.UniqueID

    suffix VerbsMenu

    LTrim(temp[menucounter].innerText.toString().toLowerCase())

    get the webpart name, possiblity is $ sign and : sign so filter it mgr1$gwpt1

    --PARAMETER INFORMATION

    ctrlID is the controlID and showMenu will contain 'false,true' type string that mean

    first string will be treated for edit menu and last string will be treated for delete menu

    */

    if(ctrlID!=null)

    {

    //if there is $ sign with the controls unique id

    if(ctrlID.indexOf('$')>0)

    {

    ctrlID=ctrlID.substring(ctrlID.indexOf(

    '$')+1,ctrlID.length);

    }

    //if there is : sign with the controls unique id

    if(ctrlID.indexOf(':')>0)

    {

    ctrlID=ctrlID.substring(ctrlID.indexOf(

    ':')+1,ctrlID.length);

    }

    }

    var doc=document.getElementById("WebPart_" + ctrlID + "VerbsMenu");

    if(doc==null || doc=="undefined")

    return;

    var arr_showMenu=showMenu.split(",");

    var temp=doc.getElementsByTagName("a");

    for(menucounter=0;menucounter<temp.length; menucounter++)

    {

    //var menuLinkText=trim(temp[menucounter].innerText).toString().toLowerCase();

    var menuLinkText=trim(temp[menucounter].title).toString().toLowerCase();

    if(menuLinkText.substring(0,4)=='edit' && !ToggleMenu(arr_showMenu[0]))

    {

    temp[menucounter].style.display=

    "none";

    }

    if(menuLinkText.substring(0,6)=='delete' && !ToggleMenu(arr_showMenu[1]))

    {

    temp[menucounter].style.display=

    "none";

    }

    }

    }

    function ToggleMenu(showMenu)

    {

    if(showMenu!=null)

    if(showMenu=="false")

    return false;

    return true;

    }

    // Removes leading whitespaces

    function LTrim( value ) {

    var re = /\s*((\S+\s*)*)/;

    return value.replace(re, "$1");

    }

    // Removes ending whitespaces

    function RTrim( value ) {

    var re = /((\s*\S+)*)\s*/;

    return value.replace(re, "$1");

    }

    // Removes leading and ending whitespaces

    function trim( value ) {

    return LTrim(RTrim(value));

    }

    </script>

     

    Regards,

    Arjun

Page 1 of 1 (7 items)