+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Telerik.Cms.Web.UI.WebEditor Issue

Telerik.Cms.Web.UI.WebEditor Issue

2 posts, 0 answered
  1. Jeffrey Monroe
    Jeffrey Monroe avatar
    7 posts
    Registered:
    06 Feb 2005
    04 Mar 2011
    Link to this post
    I have a custom type editor that does not pass the edited Value back to the control. It always returns null. I have attached code.

    CompositeControl.vb
    Imports System.Web.UI
    Imports System.ComponentModel
      
    Namespace ipObjects.Web.Sitefinity
      
        Public Class CompositeControl
            Inherits System.Web.UI.WebControls.CompositeControl
      
            Protected Overrides Sub CreateChildControls()
                Me.Controls.Add(New System.Web.UI.LiteralControl("<h1>Test Composit Control</h1>"))
      
            End Sub
      
      
            Private _PageId As Guid = Guid.Empty
            <DisplayName("Test GUID"), Category("Flash"), Localizable(True), Browsable(True), _
            Telerik.Cms.Web.UI.WebEditor("ipObjects.Web.Sitefinity.Editors.PageIdSelector, ipObjects.Web.Sitefinity"), _
            Description("Url of the SWF file.")> _
            Property PageId() As Guid
                Get
                    Return _PageId
                End Get
                Set(ByVal Value As Guid)
                    _PageId = Value
                End Set
            End Property
      
        End Class
      
    End Namespace

    PageIdSelector.vb
    Imports System
    Imports System.Collections.Generic
    Imports System.Web
    Imports Telerik.Web.UI
    Imports Telerik.Cms
    Imports Telerik.Cms.Web
    Imports System.ComponentModel
      
      
    Namespace ipObjects.Web.Sitefinity.Editors
      
        Public Class PageIdSelector
            Inherits Telerik.Cms.Web.UI.WebUITypeEditor(Of Guid)
      
            Private _cmsManager As CmsManager
            Private _cmsSiteMap As CmsSiteMapProvider
            Private _pageTree As RadTreeView
            Private _parentPages As List(Of Guid)
      
      
            Private _value As Guid = Guid.Empty
            Public Overrides Property Value() As Guid
                Get
                    Try
                        Return New Guid(_pageTree.SelectedValue)
      
                    Catch
      
                        Return _value
      
                    End Try
                End Get
                Set(ByVal _value As Guid)
                    _value = value
                End Set
            End Property
      
      
            Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
                MyBase.OnInit(e)
                _cmsManager = New CmsManager()
                _cmsSiteMap = CType(System.Web.SiteMap.Provider, CmsSiteMapProvider)
            End Sub
      
      
            Protected Overrides Sub CreateChildControls()
                Dim selectedNode As SiteMapNode = Nothing
                Dim root As RadTreeNode = Nothing
      
                Try
                    _parentPages = New List(Of Guid)
      
                    If Not Me.Value.Equals(Guid.Empty) Then
                        selectedNode = _cmsSiteMap.FindSiteMapNodeFromKey(Me.Value.ToString)
                        _parentPages = GetParents(selectedNode.ParentNode, _parentPages)
                        _parentPages.Reverse()
                    End If
      
                    Me.Controls.Add(New System.Web.UI.LiteralControl(String.Format("<div class='{0}'>", "sitemapTree")))
      
                    root = New RadTreeNode()
                    root.Text = "All Pages"
                    root.Value = Guid.Empty.ToString
                    root.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                    root.Expanded = True
                    If Value.Equals(Guid.Empty) Then
                        root.Selected = True
                    End If
      
                    _pageTree = New RadTreeView
                    AddHandler _pageTree.NodeExpand, AddressOf pageTree_NodeExpand
                    _pageTree.Nodes.Add(root)
                    LoadNodes(root)
      
                    Me.Controls.Add(_pageTree)
      
                    Me.Controls.Add(New System.Web.UI.LiteralControl("</div>"))
      
                Finally
                    root = Nothing
                    selectedNode = Nothing
      
                End Try
            End Sub
      
      
            Public Sub PreselectedValue()
                Dim node As RadTreeNode = Nothing
                Dim pageId As Guid
      
                Try
                    For Each pageId In _parentPages
                        node = _pageTree.FindNodeByValue(pageId.ToString())
                        node.Expanded = True
      
                        If node.Nodes.Count = 0 Then
                            LoadNodes(node)
                        End If
                    Next
      
                Finally
      
                End Try
            End Sub
      
      
            Private Sub LoadNodes(ByVal root As RadTreeNode)
                Dim page As ICmsPage = Nothing
                Dim node As RadTreeNode = Nothing
      
                Try
                    For Each page In _cmsManager.GetPages(New Guid(root.Value))
                        node = New RadTreeNode()
                        node.Value = page.ID.ToString
                        node.Text = page.MenuName
                        node.ToolTip = page.MenuName
      
                        If page.Pages.Count > 0 Then
                            node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack
                        End If
      
                        If page.ID.Equals(Me.Value) Then
                            node.Selected = True
                        End If
      
                        node.Expanded = True
      
                        If _parentPages.Contains(page.ID) Then
                            LoadNodes(node)
                        End If
      
                        root.Nodes.Add(node)
                    Next
      
                Finally
                    ' Cleanup
                    node = Nothing
                    page = Nothing
      
                End Try
            End Sub
      
      
            Private Function GetParents(ByVal node As SiteMapNode, ByVal parents As List(Of Guid)) As List(Of Guid)
                Dim cmsNode As CmsSiteMapNode
      
                Try
                    If Not node.Equals(node.RootNode) Then
                        cmsNode = CType(node, CmsSiteMapNode)
                        parents.Add(cmsNode.PageID)
                        parents = GetParents(node.ParentNode, parents)
                    End If
      
                    Return parents
      
                Finally
      
                End Try
      
      
            End Function
      
      
            Protected Sub pageTree_NodeExpand(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs)
                Me.LoadNodes(e.Node)
            End Sub
      
      
        End Class
      
    End Namespace
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 Mar 2011
    Link to this post
    Hello Jeffrey,

    You can take a look at this post that shows how to get/set selected value of a RadTreeNode using WebUITypeEditor.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
2 posts, 0 answered