Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andy Duff 2 posts 22 karma points
    Jun 27, 2011 @ 15:20
    Andy Duff
    0

    ContentControl accessing the properties

    Hi, I've been banging my head for about 2 hours and can't see anything in the forums.

    What I am attempting to do is remove the Save, publish to and publish buttons for certain users and I may also want to hide properties.

    So far I have created a class and inherited ApplicationBase. I’ve hooked up to the event on ContentControl.AfterContentControlLoad and can see the TabPages and all controls on them.

     

    I can recursively loop though all controls within ContentControl and get anything that implements IDataEditor, the issue is I don’t know where to get the property data for the IDataEditor. The ID of the IDataEditor is always prop_<fieldname> but I could do with more information than this including the integer ID.

    Below is a cut down version of the code ...

     Public Sub New()
    AddHandler ContentControl.AfterContentControlLoad, AddressOf ContentControlCreated
    End Sub

    Public Sub ContentControlCreated(ByVal sender As Object, ByVal e As ContentControlLoadEventArgs)
    Dim objContentControl As ContentControl = TryCast(sender, ContentControl)

    If (objContentControl IsNot Nothing) Then
    Dim arrControls() As System.Web.UI.Control = GetControls(objContentControl)
    For Each objControl As System.Web.UI.Control In arrControls
    If (TypeOf objControl Is umbraco.interfaces.IDataEditor) Then
    With DirectCast(objControl, umbraco.interfaces.IDataEditor)
    Debug.WriteLine(.Editor.ID)
    End With
    End If
    Next
    End If
    End Sub

    #Region "Controls"

    Private Function GetControls(ByVal Parent As System.Web.UI.Control) As System.Web.UI.Control()
    Dim colControls As New List(Of System.Web.UI.Control)
    ' Get all controls recursivally
    Me.GetControls(Parent, colControls)
    ' Return control list
    Return colControls.ToArray
    End Function

    Private Sub GetControls(ByVal Parent As System.Web.UI.Control, ByRef Controls As List(Of System.Web.UI.Control))
    ' loop through all controls
    For Each objControl As System.Web.UI.Control In Parent.Controls
    Controls.Add(objControl)
    ' recursivally get all
    Me.GetControls(objControl, Controls)
    Next
    End Sub

    #End Region

     

    Many thanks

     

    Andy

  • Andy Duff 2 posts 22 karma points
    Jun 27, 2011 @ 16:59
    Andy Duff
    0

    After looking at this a bit more I can get the document and lookup the property information by removing the prop_ and using that value as the property alias. But is there a better way?

    Thanks

     

    Andy

Please Sign in or register to post replies

Write your reply to:

Draft