... did not implement ICallbackEventHandler message

7 posts, 0 answers
  1. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 27 Dec 2008 Link to this post

    Hi,

    Just upgraded to the Premium Suite for some Xmas development work.

    I have created a server-side control that renders a TreeView whose nodes are set to be populated on Callback.
    On expanding the first node, I have the following error message popping up:

    The target 'ctl00$ctl01$mainContentArea$treeNavigation$kbTreeView' for the callback could not be found or did not implement ICallbackEventHandler.

    My server-side control is below:

    1  
    2     [DefaultProperty("Text")] 
    3     [ToolboxData("<{0}:KnowledgeBaseTree runat=server></{0}:KnowledgeBaseTree>")] 
    4     public class KnowledgeBaseTree : WebControl, ICallbackEventHandler 
    5     { 
    6  
    7  
    8 // ... snip ... 
    9  
    10         protected override void CreateChildControls() 
    11         { 
    12 // ... snip  ... 
    13  
    14 Controls.Add(BuildContentTreeView(baseUrl,session)); 
    15  
    16          
    17         } 
    18  
    19         private RadTreeView BuildContentTreeView(string baseUrl, ISession session) 
    20         { 
    21  
    22 // ... snip ... 
    23             RadTreeView radTreeView = new RadTreeView(); 
    24             radTreeView.NodeExpand += new RadTreeViewEventHandler(radTreeView_NodeExpand); 
    25             radTreeView.ID = "kbTreeView"
    26  
    27             IPost[] posts = _cachedBinder.GetRootPosts(null, TimeSpan.Zero); 
    28  
    29                 foreach (IPost post in posts) 
    30                 { 
    31  
    32 // ... snip ... 
    33                         RadTreeNode radTreeNode = new RadTreeNode(post.Title, post.ID.ToString(), postUrl + ".aspx"); 
    34                                 }                        
    35             return radTreeView; 
    36         } 
    37  
    38         void radTreeView_NodeExpand(object sender, RadTreeNodeEventArgs e) 
    39         { 
    40             Guid postId = new Guid(e.Node.Value); 
    41  
    42 // ... snip ... 
    43                     // get child nodes 
    44                     IPost[] childPosts = selectedPost.GetChildPosts(null, TimeSpan.Zero); 
    45                     foreach (IPost childPost in childPosts) 
    46                     { 
    47                         string childPostUrl = Path.Combine(basePostUrl, childPost.UrlKey); 
    48                         RadTreeNode childTreeNode = new RadTreeNode(childPost.Title, childPost.ID.ToString(), childPostUrl + ".aspx"); 
    49                         childTreeNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; 
    50                         childTreeNode.Nodes.Add(childTreeNode);                          
    51                     } 
    52         } 
    53  
    54  
    55
    56  
    57  

    The serverside control KnwoeldgeBaseTree (represented by the class above) is within the Page as usual:

    <KB:KnowledgeBaseTree id="knowledgeBaseTree" runat="server" />

    So, as far as I know, I'm in the right place as far as the page lifecycle is concerned.

    I've also tried rendering the tree in the Init stage of the server control. No change.

    Can you please help me fix this?

  2. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 27 Dec 2008 Link to this post

    Ok, I was being a bit of a moron.

    For others' benefit, make sure you implement INamingContainer on your server control - something I always forget to do!

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Suraj
    Suraj avatar
    14 posts
    Member since:
    Feb 2008

    Posted 18 Feb 2009 Link to this post

    Iam trying to do similar stuff but when I expand the node it is not hitting the Exapand Mode Event handler. Can you let me know if you figured how to do this.
  5. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 18 Feb 2009 Link to this post

    As long as the server control is present in the page on the initial rendering and subsequent rendering (after postback), and your server control implements INamingContainer, it should work.

    I did get it working after checking my server control implemented INamingContainer. Note that I was writing a server control that wraps Teleriks TreeView.

    If this doesn't help, let me know and I'll see if I can knock a demo class up.
  6. Suraj
    Suraj avatar
    14 posts
    Member since:
    Feb 2008

    Posted 18 Feb 2009 Link to this post

    ok. This is what I am doing in the code. Let me know what you think.

      public class ItemTree : System.Web.UI.WebControls.WebControl,
        ICallbackEventHandler,
        INamingContainer
      {
        
        protected override void CreateChildControls()
        {
          CreateTree();
        }

        private void CreateTree()
        {
          using (RadTreeView _RadTreeView = new RadTreeView())
          {
            _RadTreeView.NodeExpand += new RadTreeViewEventHandler(_RadTreeView_NodeExpand);
            _RadTreeView.ID = "_RadTreeView";
            RadTreeNode _RadTreeNode = new RadTreeNode();
            _RadTreeNode.Text = "Root";
            _RadTreeNode.Value = "0";
            _RadTreeNode.Expanded = true;
            _RadTreeView.Nodes.Add(_RadTreeNode);
            LoadInitialItems(_RadTreeNode);
            
            this.Controls.Add(_RadTreeView);
          }
        }
        private void _RadTreeView_NodeExpand(object sender,
                                             RadTreeNodeEventArgs e)
        {
          for (int i = 0; i < 10; i++)
          {
            RadTreeNode oItemNode;
            oItemNode = oMakeItemNode(i);

            e.Node.Nodes.Add(oItemNode);
          }
          e.Node.Expanded = true;
        }

        private void LoadInitialItems(
      RadTreeNode oParentNode)
        {
          for (int i = 0; i < 10;i++ )
          {
            RadTreeNode oItemNode;
            oItemNode = oMakeItemNode(i);

            oParentNode.Nodes.Add(oItemNode);
          }
        }

     
        private RadTreeNode oMakeItemNode(int i)
        {
          RadTreeNode oItemNode;
          string ItemText = string.Empty;
          
          oItemNode = new RadTreeNode(i.ToString(),
                                      i.ToString()
            );
          
            oItemNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;


         
          return oItemNode;
        }


        #region ICallbackEventHandler Members

        ///<summary>
        ///Processes a callback event that targets a control.
        ///</summary>
        ///
        ///<param name="eventArgument">A string that represents an event argument to pass to the event handler.</param>
        void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {

         }
         ///<summary>
        ///Returns the results of a callback event that targets a control.
        ///</summary>
        ///
        ///<returns>
        ///The result of the callback.
        ///</returns>
        ///
        string ICallbackEventHandler.GetCallbackResult()
        {
          return "";
        }

        #endregion
      }
  7. Nathan J Pledger
    Nathan J Pledger avatar
    95 posts
    Member since:
    Apr 2006

    Posted 18 Feb 2009 Link to this post

    Have you tried taking your instantiation of the RadTreeView out of the using () {} statement? When control falls out of the scope of this statement, the control may have been disposed?
  8. Suraj
    Suraj avatar
    14 posts
    Member since:
    Feb 2008

    Posted 18 Feb 2009 Link to this post

    Thanks for the suggestion. That's what exactly happening
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017