inherited treeview throws exception when using LoadXmlString

3 posts, 1 answers
  1. wg
    wg avatar
    30 posts
    Member since:
    Jul 2006

    Posted 02 Jun 2013 Link to this post

    Hi,

    When I use my own TreeView which is inherited from RadTreeView, it doesn't work like the base class and throw exception. 
    My version is 2013.1.403.40

    First I create the new TreeView, very simple.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Web.UI;
     
    namespace TreeViewTest
    {
        public class XTreeView:RadTreeView
        {
        }
    }

    Then I drag it to a aspx page. on the code behind. I write code like this.
                    string xmlStr = @"<Tree>
      <Node Text='Desktop' Expanded='True' ToolTip='Desktop' ImageUrl='~/TreeView/Img/Vista/desktop.png'>
        <Node Text='Administrator' ImageUrl='~/TreeView/Img/Vista/folder-personal.png' Expanded='True'>
          <Node Text='AppData' ImageUrl='~/TreeView/Img/Vista/folder.png'>
            <Node Text='Microsoft'  ImageUrl='~/TreeView/Img/Vista/folder.png'/>
          </Node>
          <Node Text='Contacts' ImageUrl='~/TreeView/Img/Vista/folder-contacts.png' />
          <Node Text='Downloads'  ImageUrl='~/TreeView/Img/Vista/folder-open.png'/>
          <Node Text='Documents' ImageUrl='~/TreeView/Img/Vista/folder-documents.png' Selected='True' />
          <Node Text='Favorites' ImageUrl='~/TreeView/Img/Vista/folder-favorites.png' >
            <Node Text='Links'  ImageUrl='~/TreeView/Img/Vista/folder.png'/>
          </Node>
          <Node Text='Music' ImageUrl='~/TreeView/Img/Vista/folder-music.png' />
          <Node Text='Pictures' ImageUrl='~/TreeView/Img/Vista/folder-pictures.png' />
          <Node Text='Saved Games' ImageUrl='~/TreeView/Img/Vista/folder-open.png'  />
          <Node Text='Searches' ImageUrl='~/TreeView/Img/Vista/searches.png'  >
            <Node Text='History'  ImageUrl='~/TreeView/Img/Vista/folder.png'/>
          </Node>
          <Node Text='Videos' ImageUrl='~/TreeView/Img/Vista/folder-videos.png' />
        </Node>
        <Node Text='Computer' ToolTip='My Computer'  ImageUrl='~/TreeView/Img/Vista/computer.png' Expanded='True' >
          <Node Text='WebServer (\\10.0.0.80) (W:)' ImageUrl='~/TreeView/Img/Vista/network-drive.png' />
          <Node Text='Local Disk (C:)' ImageUrl='~/TreeView/Img/Vista/system-drive.png' Expanded='True' >
            <Node Text='inetpub'  ImageUrl='~/TreeView/Img/Vista/folder.png' Expanded='True'>
              <Node Text='AdminScripts'  ImageUrl='~/TreeView/Img/Vista/folder.png'></Node>
            </Node>
          </Node>
        </Node>
      </Node>
    </Tree>";
                    XTreeView1.LoadXmlString(xmlStr);

    Just xml string and LoadXmlString. It gives me error.  The same code works well with base RadTreeView.

    Could you please take a look at it?

    Thank you very much.

    Bill
  2. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 05 Jun 2013 Link to this post

    Hello Bill,

    I would like to clarify that some of the attributes are not inherited directly and need to be declared explicitly. Please add the XML serialization attribute [XmlRoot("Tree")]  as shown in the code snippet below:
    //code behind
    [XmlRoot("Tree")]
    public class XTreeView : RadTreeView
    {
    }


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. wg
    wg avatar
    30 posts
    Member since:
    Jul 2006

    Posted 05 Jun 2013 Link to this post

    Yeah! It works a treat! Thank you vey much. It really confused me long time.
Back to Top