Adding Problem setting EventHandlers in Code Behind Callbacks?

5 posts, 0 answers
  1. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 15 Sep 2009 Link to this post

    Hi,

    Using the standard RadTreeView examples (.NET35, Ajax RadView Q2 2009).
    I can set event handlers fine in the markup, but as soon as I try to set an event handler in a callback, it doesn't work.

    For example, the following does not work:
    .aspx:
        <telerik:RadTreeView ID="RadTreeView2" Skin="Black"
            OnNodeExpand="RadTreeView2_NodeExpand"
            runat="server">... </telerik:RadTreeView>

    .cs:


        protected void RadTreeView2_NodeExpand(object sender, RadTreeNodeEventArgs e)
        {
                RadTreeView2.EnableDragAndDrop = true;
                RadTreeView2.NodeDrop += new RadTreeViewDragDropEventHandler(this.RadTreeView2_NodeDrop);
        }
       private void RadTreeView2_NodeDrop(object sender, RadTreeNodeDragDropEventArgs e) {}



    any idea why? I thought it was perhaps a view state problem, but enabling it explicitly didn't change anything.

    If I put the handler assignment in the Page_Load or Page_Init, it works.

    In short: what do I need to do to dynamically enable/disable drag-drop features on nodes?

    Thanks!
    R





  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 15 Sep 2009 Link to this post

    Hi Richard,

    Event handlers must be assigned always (on every page_load or page_init) in order to work. The reaso is that event handlers are not persisted in viewstate. To control the drag and drop behavior I suggest you use the EnableDragAndDrop property of RadTreeView. The NodeDrop event handler should be always assigned.

    Regards,
    Albert,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 15 Sep 2009 Link to this post

    Thanks Albert,

    >>To control the drag and drop behavior I suggest you use the EnableDragAndDrop property of RadTreeView.
    That's what I tried first, but it doesn't work dynamically either. If I put:
    RadTreeView2.EnableDragAndDrop = true;
    in a callback (i.e. anywhere besides the page initialization), it doesn't work. Any ideas?

    After taking a closer look at the Ajax traffic (I'm using ServerCallback mode), it appears that you are sending the ViewState down to the server in the POST, and returning JSON that contains only the node content  and some settings like this:

    s[{"selected":1,"skip":1},{},{"value":"rcvalue","expandMode":2,"allowDrag":false,"category":"rccat","toolTip":"rctooltip"},{},{"value":"rcvalue","category":"rccat","toolTip":"rctooltip"}]_$$_<li class="rtLI"><div class="rtTop rtSelected"> ...
    

    That is great for performance, but these settings are apparently not transported for all nodes or not for the TreeView itself? In any case, the ones I set are apparently not being applied client-side... and it doesn't look like they are present anywhere in the client-server communication.

    Tips?

    Thanks!
    R



  5. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 15 Sep 2009 Link to this post

    Hi,

    Using a combination with an UpdatePanel is apparently a solution to this situation. Better, though, would be for the Node-callbacks to send the modified Node settings back in the JSON and apply them client-side.
    My notes:
            // State/settings update in server-side callback:
            // To get all state updated (settings, visibility etc.) use the combination:
            //      UpdatePanel in ASPX and n2.ExpandMode = TreeNodeExpandMode.ServerSide; for this node.
            //      Note, this is the only reason for the UpdatePanel in the ASPX.
            // To get only the node content data, and some of the state updated (with significantly
            //      less Ajax-Data overhead), remove the UpdatePanel in ASPX, and use
            //      n2.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; for this node
            // So, depending on your needs...

    Thoughts?

    Thanks,
    R



  6. Vesko
    Vesko avatar
    122 posts
    Member since:
    Mar 2009

    Posted 17 Sep 2009 Link to this post

    You can check this blog post

    RadTreeView for ASP.NET Ajax Load On Demand Modes - why so many?



    It describes the pros and cons of the different load on demand modes of the treeview.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017