This is a migrated thread and some comments may be shown as answers.

Adding Problem setting EventHandlers in Code Behind Callbacks?

4 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Richard asked on 15 Sep 2009, 03:51 PM
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





4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 15 Sep 2009, 03:57 PM
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.
0
Richard
Top achievements
Rank 2
answered on 15 Sep 2009, 04:15 PM
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



0
Richard
Top achievements
Rank 2
answered on 15 Sep 2009, 07:53 PM
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



0
Vesko
Top achievements
Rank 2
answered on 17 Sep 2009, 12:40 PM
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.
Tags
TreeView
Asked by
Richard
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Richard
Top achievements
Rank 2
Vesko
Top achievements
Rank 2
Share this question
or