Problems activating dropdowns in a wrapper class

Last post 10-19-2007, 6:26 PM by Flintstone. 2 replies.
Sort Posts: Previous Next
  •  10-18-2007, 11:12 AM 34413

    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.
  •  10-19-2007, 1:55 PM 34445 in reply to 34413

    Re: Problems activating dropdowns in a wrapper class

    Please use the following code:
     
    If Not Page.IsPostBack Then
      If Not Editor1.ToolControls("FontSize") Is Nothing Then

          Dim dropdown As CuteEditor.RichDropDownList
          Dim richitem As CuteEditor.RichListItem

          dropdown = DirectCast(Editor1.ToolControls("FontSize").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)

          'add value only
          dropdown.Items.Add("1")

          'add text and value
          dropdown.Items.Add("2 (10pt)","2")

          'Add html and text and value
          dropdown.Items.Add("<span style='font-size:18pt'>5 </span>(18pt)", "5 (18pt)", "5")

      End If
    End If



    Font Size Dropdown Customization

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  10-19-2007, 6:26 PM 34452 in reply to 34445

    Re: Problems activating dropdowns in a wrapper class

    Adam, thanks for the prompt reply, I managed to get my wrapper working earlier today, this is the first chance I have had to leave feedback:

    • The reason I received the error was because I had used ConfigurationPath to set the configuration. It seems that if an item such as "LinkTree" is missing from this ConfigurationPath file then any attempt to cast it to CuteEditor.TreeDropDownList results in an "Invalid Cast Exception." In this situation setting TemplateItemList seems to result in malformed controls when the control is missing from the ConfigurationPath file.

    • In your example which is also in the dev manual you use the following line:

      dropdown.Items.Add("<span style='font-size:18pt'>5 </span>(18pt)", "5 (18pt)", "5")

      The HTML in the above line is rendered as text and not HTML so the span tag is of no real use here.

    • The manual also references the button control "Links" numerous times ... I believe this should be "LinkTree"

    I hope this is useful to you.
View as RSS news feed in XML