NullReference when customizing Links ddl

Last post 01-25-2006, 4:11 PM by kcmonster58. 7 replies.
Sort Posts: Previous Next
  •  01-25-2006, 2:23 PM 15118

    NullReference when customizing Links ddl

    The following line gives me a nullreference error :

    dropdown = DirectCast(Editor1.ToolControls("Links").Control, CuteEditor.RichDropDownList)
     
    I am using the code given in the example of how to progrommatically set the links in the ddl. What I don't understand is, I get no error at runtime on these lines:
     
       Editor1.Text = ...
        Editor1.WysiwygModeCss = ...
     
    I have tried this code in several subroutines such as Page_load, Panel_preRender, etc and always get the same results. What am I missing here?
     
  •  01-25-2006, 2:29 PM 15119 in reply to 15118

    Re: NullReference when customizing Links ddl

    The links dropdown has been changed to TreeDropDownList
     
    Dim tdd As CuteEditor.TreeDropDownList
      
    tdd = DirectCast(Editor1.ToolControls("LinkTree").Control, CuteEditor.TreeDropDownList)
     
    The following example shows you how to populate the linktree:
     
    <%@ Page Language="VB" %>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <html>
        <head>
      <title>ASP and ASP.NET WYSIWYG Editor - How to dynamically populate the tree view dropdown menu? </title>
      <link rel="stylesheet" href="../../example.css" type="text/css" />
     </head>
        <body >
            <form runat="server">
       <h2>How to dynamically populate the tree view dropdown menu?</h2> <hr>
       <br />
       <h4>Populate the link tree view dropdown menu</h4>
       <CE:Editor EditorWysiwygModeCss="../../example.css" id="Editor1" UseRelativeLinks="true" runat="server" ></CE:Editor><br />
       <hr>
       <h4>Add new tree view dropdown menu</h4>
       <CE:EDITOR id="Editor2" EditorWysiwygModeCss="../../example.css" Autoconfigure="Minimal" runat="server"></CE:EDITOR>
     
      </form>
     </body>
    </html>

    <script runat="server">
     Public Sub Page_Load(sender As object, e As System.EventArgs)
     
      If Not Page.IsPostBack Then   
       Editor1.Text = "Type Here"
       Editor2.Text = "Type Here"
      End If
      
      
         'Get the TreeDropDownList
      'check <item type="treedropdown" name="LinkTree" text="((Links))" width="50" command="InsertLink" />
      'check Common.config
      
      Dim tdd As CuteEditor.TreeDropDownList
      
      tdd = DirectCast(Editor1.ToolControls("LinkTree").Control, CuteEditor.TreeDropDownList)
     
      'clear the items from configuration files
      'see Configuration/Shared/Common.config
      'tdd.Items.Clear()
         
      'Add items by code
      Dim rootitem As CuteEditor.TreeListItem
      rootitem=new CuteEditor.TreeListItem("Root")
      
      rootitem.Selectable=false
      tdd.Items.Add(rootitem)
      rootitem.Items.Add("Asp<font color=red>.Net</font>","Asp.Net","http:'asp.net")
      rootitem.Items.Add("DotNetNuke.Net","DotNetNuke.Net","http:'DotNetNuke.com")
      rootitem.Items.Add("CuteSoft","CuteSoft","http:'CuteSoft.net")
     
     
      Dim tc as CuteEditor.ToolControl
      tc = Editor1.ToolControls("insertcustombutonhere")
      
      If Not tc Is Nothing Then
       
       Dim ddl As CuteEditor.TreeDropDownList
       ddl=new TreeDropDownList(Editor2)
       ' ddl.RenderItemBorder=true
       ddl.CssClass="CuteEditorDropDown"
       'set the command and event handler
       ddl.Attributes("Command")="PasteHTML"
       'each item's value is just the parameter of Command
       ddl.Attributes("onchange")="CuteEditor_DropDownCommand(this,'"&ddl.Attributes("Command")&"')"
       'set the title
       ddl.RootItem.Text="MyTree"
       
       'Add items recursive
       AddItems(ddl.Items,"~/Uploads")   
       
       Dim index As Integer
             index = Editor2.ToolControls.IndexOf("insertcustombutonhere") + 1
           
       Editor2.InsertToolControl(index,"MyTree",ddl) 
      End If
      
     End Sub
     
     Public Sub AddItems(ByVal items As CuteEditor.TreeListItemCollection,ByVal virpath As string)
      virpath=virpath.TrimEnd("/"c)
     
      Dim dir as string
      dir=Server.MapPath(virpath) 
      
      Dim files() As String
      files=System.IO.Directory.GetFiles(dir)
      
      If files.Length=0 Then
       return 'Skip empty folder
      End If
      
      
            Dim diritem As CuteEditor.TreeListItem
            diritem = New CuteEditor.TreeListItem(System.IO.Path.GetFileName(dir))
      diritem.Selectable=false
      items.Add(diritem)
       
       
      dim subdir as string
      dim subfile as string
     
      'for each sub directories
      For each subdir in System.IO.Directory.GetDirectories(dir)
      
       dim subdirname as string
       dim subvirpath as string
       subdirname=System.IO.Path.GetFileName(subdir)
       subvirpath=virpath & "/" & subdirname
      
       ' Recursive .
       AddItems( diritem.Items, subvirpath )
      Next
     
     
      For each subfile in files
      
       dim filename as string
       dim filepath as string
       dim filetype as string
       dim subdirname as string
       subdirname=System.IO.Path.GetFileName(subdir)
       
       filename=System.IO.Path.GetFileName(subfile)
       filepath=ResolveUrl(virpath).TrimEnd("/"c) & "/" & filename
       filetype=System.IO.Path.GetExtension(filename).ToLower()
       
       If filetype=".gif" or filetype=".jpg" or filetype=".png" Then
        Dim fileitem As CuteEditor.TreeListItem
        fileitem=new CuteEditor.TreeListItem(filename,"<img src='" & filepath & "' />")
        diritem.Items.Add(fileitem)
       End If
      Next
     
     End Sub 
     
    </script>

    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

  •  01-25-2006, 2:51 PM 15122 in reply to 15119

    Re: NullReference when customizing Links ddl

    OK, will this actually change the links in the default LinkTree (as defined in the config file) or will this only create a new linktree. all I really want to do is change the links in the default tree, but I can't seem to do that using the following code:
     
    ....

    objRead = cmd.ExecuteReader

    Dim tdd As CuteEditor.TreeDropDownList

    tdd = DirectCast(Editor1.ToolControls("LinkTree").Control, CuteEditor.TreeDropDownList)

    tdd.Items.Clear()

    While objRead.Read()

    Dim rootitem As CuteEditor.TreeListItem

    rootitem = New CuteEditor.TreeListItem(objRead("title").ToString, objRead("title").ToString, "~/default.aspx?pageid=" & objRead("id"))

    tdd.Items.Add(rootitem)

    End While

    objRead.Close()
    ..........
     
    I get no errors, but the links are still the default ones from the config file
     
    P.S. I am running this code in the Editor1_Load sub
  •  01-25-2006, 3:08 PM 15123 in reply to 15122

    Re: NullReference when customizing Links ddl

  •  01-25-2006, 3:09 PM 15124 in reply to 15123

    Re: NullReference when customizing Links ddl

    Here it is:

    Protected Sub Editor1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Editor1.Load
            Dim connstr As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
            Dim sqlConn As New SqlConnection(connstr("SRHSWeb").ConnectionString)
            Dim strsql As String
            Dim cmd As SqlCommand
            Dim objRead As SqlDataReader
            Dim titlefld As String
            sqlConn.Open()
            If editpageid > 0 Then
                strsql = "select body,versiontitle,title,right_content from editpages where id = " & Session("editpageid")
                titlefld = "versiontitle"
            Else
                strsql = "select body,title,right_content from pages where id = " & Session("pageid")
                titlefld = "title"
            End If
            cmd = New SqlCommand(strsql, sqlConn)
            objRead = cmd.ExecuteReader
            If objRead.HasRows Then
                objRead.Read()
                Editor1.Text = objRead("body").ToString()
                VersionTitle.Text = objRead(titlefld).ToString()
                pageTitle.Text = objRead("title").ToString()
                Editor2.Text = objRead("right_content").ToString
            End If
            objRead.Close()
            cmd.Dispose()
            strsql = "select * from pages"
            cmd = New SqlCommand(strsql, sqlConn)
            objRead = cmd.ExecuteReader
            Dim tdd As CuteEditor.TreeDropDownList
            tdd = DirectCast(Editor1.ToolControls("LinkTree").Control, CuteEditor.TreeDropDownList)
            tdd.Items.Clear()
            While objRead.Read()
                Dim rootitem As CuteEditor.TreeListItem
                rootitem = New CuteEditor.TreeListItem(objRead("title").ToString, objRead("title").ToString, "~/default.aspx?pageid=" & objRead("id"))
                tdd.Items.Add(rootitem)
            End While
            objRead.Close()
     
            sqlConn.Close()
        End Sub
  •  01-25-2006, 3:31 PM 15126 in reply to 15124

    Re: NullReference when customizing Links ddl

    Where did you call Editor1_Load sub?
     
    Can you post the whole code behind page?
     
     

    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

  •  01-25-2006, 3:34 PM 15127 in reply to 15126

    Re: NullReference when customizing Links ddl

    There is ALOT of code in the code behind page. Editor1_Load is automatically called when the editor loads.
  •  01-25-2006, 4:11 PM 15133 in reply to 15127

    Re: NullReference when customizing Links ddl

    Figured it out....the editor was reading its config file after my code ran.
     
    Looks like the best time to do this in on the Editor1_Initialized event.
View as RSS news feed in XML