Problems activating dropdowns in a wrapper class

  •  10-18-2007, 11:12 AM

    Problems activating dropdowns in a wrapper class

    I will try to keep this short.  I use vb.net but no code behind, well not in the usual sense ... here is my aspx page:

    <%=objInterface.GetTextAsHTML("txtHTMLTitle")%>

    <%@ Page Language="VB" explicit="true" autoeventwireup="false" enableviewstate="false" validateRequest="false" %><%@ Import Namespace="Company.Product" %>
    <html>
    <head>
                <title>Test</title>
    </head>
    <body margin="0" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bottommargin="0" rightmargin="0">
                            Dim linkListDict As New IntCELinkListItemSortableDictionary
                            linkListDict.Add(0, New CELinkListItem("google.co.uk", "http://www.google.co.uk"))
                            linkListDict.Add(1, New CELinkListItem("comartis.com", "http://www.comartis.com"))
                            Dim cew As New CuteEditorWrapper("Editor2")
                            cew.Text="Yes, I will allow you to type text here."
                            cew.AddButton(basGlobals.CEButton.FontSize)
                            cew.AddButton(basGlobals.CEButton.Bold)
                            cew.AddButton(basGlobals.CEButton.Italic)
                            cew.SetLinkList(linkListDict)
                            cew.AddButton(basGlobals.CEButton.Links)
                            cew.ProcessButtons()
                            cew.SetFontSizeDropdown(2,4,6,7,9)                                               

                            Response.Write(cew.Draw(Me.Page))
    </body>


    I use code behind in a file inside of the namespace specified at the top of the aspx file. I am writing a wrapper which I will use to implement the editor in an app. The Dictionaries are our own typed dictionaries ... basically the ones I have used are dictionaried with Integers as the keys and the relevant class as the values:

    Imports System.Text
    Imports System.IO
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.Util

    Public Class CuteEditorWrapper
    Private buttonDict As New Company.Lib.Dictionaries.StringDictionary

    Public Enum WrapperBreakElement
    ekbDiv
    ekbP
    ekbBR
    End Enum

    Private ce As CuteEditor.Editor

    Private Shared sEditorWysiwygModeCSS As String = "CuteEditor_Support/iqBoxDefault.css"
    Private Shared sConfigurationPath As String = "~/CuteEditor_Support/iqBoxDefault.config"

    Public Sub New()
    ce = New CuteEditor.Editor
    If Len(sEditorWysiwygModeCSS) > 0 Then ce.EditorWysiwygModeCss = sEditorWysiwygModeCSS
    If Len(sConfigurationPath) > 0 Then ce.ConfigurationPath = sConfigurationPath
    'ce.RenderRichDropDown = false ' higher performance, less sexy. In this case, the links dropdown is not rendered :-(
    ce.BreakElement = CuteEditor.BreakElement.P ' default is


    End Sub

    Public Sub New(ByVal pID As String)
    MyClass.New()
    ID = pID
    End Sub

    Public Property ID() As String
    Get
    Return ce.ID
    End Get
    Set(ByVal Value As String)
    ce.ID = Value
    End Set
    End Property

    Public Property Text() As String
    Get
    Return ce.Text
    End Get
    Set(ByVal Value As String)
    ce.Text = Value
    End Set
    End Property

    Public Sub AddButton(ByVal key As CEButton)
    Dim EnumName As String = CType(key, CEButton).ToString()

    If Not buttonDict.Contains(EnumName) Then buttonDict.Add(EnumName, EnumName)
    End Sub

    Public Sub RemoveButton(ByVal key As CEButton)
    Dim EnumName As String = CType(key, CEButton).ToString()

    If buttonDict.Contains(EnumName) Then buttonDict.Remove(EnumName)
    End Sub

    Public Sub ProcessButtons()
    Dim sb As New System.Text.StringBuilder

    For Each key As String In buttonDict.KeyArray
    If sb.Length > 0 Then sb.Append(", ")
    sb.Append(key)
    Next

    ce.TemplateItemList = sb.ToString
    End Sub

    Public Sub SetFontSizeDropdown(ByVal ParamArray fontSize As Integer())
    If Not ce.ToolControls("FontSize") Is Nothing Then
    Dim dropdown As CuteEditor.RichDropDownList
    Dim richitem As CuteEditor.RichListItem

    SetUpRichDropDownList(dropdown, richitem, "FontSize")

    For Each size As Integer In fontSize
    dropdown.Items.Add("" & size & "pt ")
    Next
    End If
    End Sub

    Public Sub SetLinkList(ByVal pLinkList As IntCELinkListItemSortableDictionary)
    If Not ce.ToolControls("LinkTree") Is Nothing Then
    Dim tdd As CuteEditor.TreeDropDownList
    Dim richitem As CuteEditor.RichListItem
    tdd = DirectCast(ce.ToolControls("LinkTree").Control, CuteEditor.TreeDropDownList)

    'clear the items from configuration files
    tdd.Items.Clear()

    'Add items by code
    Dim rootitem As CuteEditor.TreeListItem
    rootitem = New CuteEditor.TreeListItem("Root")
    rootitem.Selectable = False
    tdd.Items.Add(rootitem)

    Dim keys() As Integer = pLinkList.KeyArray
    For i As Integer = 0 To keys.Length - 1
    Dim li As CELinkListItem = pLinkList.Item(keys(i))
    rootitem.Items.Add(li.Title, li.Title, li.Value)
    Next
    End If
    End Sub

    Private Sub SetUpRichDropDownList(ByRef dropdown As CuteEditor.RichDropDownList, ByVal richitem As CuteEditor.RichListItem, ByVal toolControlString As String)
    dropdown = DirectCast(ce.ToolControls(toolControlString).Control, CuteEditor.RichDropDownList)

    'the first item is the caption
    richitem = dropdown.Items(0)

    'clear the items from configuration files
    dropdown.Items.Clear()

    'add the caption
    dropdown.Items.Add(richitem)
    End Sub

    Public Function Draw(ByVal pPage As System.Web.UI.Page) As String
    Dim i As Integer = ce.ToolControls.Count ' dummy code

    Dim htx As HttpContext = HttpContext.Current

    Dim sb As New StringBuilder
    Dim sw As New StringWriter(sb)
    Dim htw As New HtmlTextWriter(sw)
    Dim pg As System.Web.UI.Page = pPage

    Dim plh As New System.Web.ui.WebControls.PlaceHolder

    plh.Page = pg
    plh.Controls.Add(ce)

    ce.Focus = False

    ce.RenderControl(htw)

    htw.Flush()
    htw.Close()
    sw.Flush()
    sw.Close()

    Return sb.ToString
    End Function
    End Class

    Public Class CELinkListItem
    Private mTitle As String
    Private mValue As String

    Public Sub New(ByVal pTitle As String, ByVal pValue As String)
    mTitle = pTitle
    mValue = pValue
    End Sub

    Public ReadOnly Property Title() As String
    Get
    Return mTitle
    End Get
    End Property

    Public ReadOnly Property Value() As String
    Get
    Return mValue
    End Get
    End Property
    End Class


    My problem is that buttons bold, italic etc. are rendered perfectly okay, The text is added correctly but the font size dropdown gives an invalid cast exception  and the link list does not appear. I know I must be misunderstanding something ... why does this not work.
View Complete Thread