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

AllowEdit ignored in RadTreeView

11 Answers 170 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Phil C
Top achievements
Rank 2
Phil C asked on 23 Jun 2008, 06:01 PM
We can edit the Node name inside the treeview using the AllowNodeEditing which is great, however I need to disable this for some types of Node.

There is the property AllowEdit which should do exactly that. Only it doesn't - it is just ignored and the node can be edited as normal. Dowhh!

11 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 24 Jun 2008, 07:17 AM
Hello Phil C,

I tried to reproduce the problem (using the SP2 release), but to no avail.

Here is my test code:

<telerik:RadTreeView ID="RadTreeView1"   
    runat="server"   
    AllowNodeEditing="true">  
    <Nodes> 
        <telerik:RadTreeNode Text="Can be edited"></telerik:RadTreeNode> 
        <telerik:RadTreeNode Text="Can not be edited" AllowEdit="false"></telerik:RadTreeNode> 
    </Nodes> 
</telerik:RadTreeView> 

Here the second node cannot be edited while the first can.

What is different in your scenario?

All the best,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil C
Top achievements
Rank 2
answered on 24 Jun 2008, 08:34 AM
Thanks for trying the base Veskoni. Just upgraded to 619 (SP2) but same prob. The difference is I am populating dynamically not declaratively. Here's a simple version with the problem, based on a telerik example:

<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <script type="text/javascript"
        function onClientNodeClicking(sender, eventArgs) 
        { 
            var node = eventArgs.get_node();  
           node.expand();  
        } 
    </script> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"
    </asp:ScriptManager> 
    <div> 
    <!-- OnClientNodeClicking="onClientNodeClicking" OnNodeClicked="NodeClicked" removed for clarity of AllowEdit="false" problem --> 
    <telerik:RadTreeView id="RadTreeView1" runat="server" 
        AllowNodeEditing="True"
        <Nodes> 
            <telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack"  
                Text="Root RadTreeNode1"
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack"  
                Text="Root RadTreeNode2"
            </telerik:RadTreeNode> 
        </Nodes> 
        <CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation> 
 
        <ExpandAnimation Duration="100"></ExpandAnimation> 
    </telerik:RadTreeView> 
    </div> 
    </form> 
</body> 
</html> 

Code is:
Imports Telerik.Web.UI 
 
Partial Class RadTreeView_145251_Default 
    Inherits System.Web.UI.Page 
 
    Protected Sub RadTreeView1_NodeExpand(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand 
        Dim node As RadTreeNode = New RadTreeNode("node" & e.Node.Level) 
        node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack 
        e.Node.AllowEdit = False 'IGNORED 
        e.Node.Nodes.Add(node) 
    End Sub 
 
    Protected Sub RadTreeView1_NodeEdit(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadTreeNodeEditEventArgs) Handles RadTreeView1.NodeEdit 
        e.Node.Text = e.Text 'Allows it! 
    End Sub 
 
End Class 



0
Veselin Vasilev
Telerik team
answered on 24 Jun 2008, 09:07 AM
Hello Phil C,

In this expand mode (either ServerSideCallBack or ServerSide or WebService) the changes made to the expanded node (the parent node) will not update it. You can make changes only to the child nodes that are to be added to the expanded node. 

You can achieve the task client-side: subscribe to the OnClientNodePopulated event and define its handler as follows: 

<script type="text/javascript">  
function OnClientNodePopulatedHandler(sender, eventArgs)  
{  
    var parentNode = eventArgs.get_node();  
    parentNode.set_allowEdit(false);  
}  
</script>   

I hope this helps.

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil C
Top achievements
Rank 2
answered on 24 Jun 2008, 10:29 AM
OK, maybe missing something here but adding this clientside setting through OnClientNodePopulated doesn't work (ie does not override the initial declarative  AllowNodeEditing):

<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <script type="text/javascript">  
function OnClientNodePopulatedHandler(sender, eventArgs)    
    {    
    var parentNode = eventArgs.get_node();    
    parentNode.set_allowEdit(false);    
    }    
 
function onClientNodeClicking(sender, eventArgs)  
    {  
        var node = eventArgs.get_node();   
       node.expand();   
    }  
    </script> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <div> 
    <!-- OnClientNodeClicking="onClientNodeClicking" OnNodeClicked="NodeClicked" removed for clarity of AllowEdit="false" problem --> 
    <telerik:RadTreeView id="RadTreeView1" runat="server" 
        AllowNodeEditing="True" 
        OnClientNodePopulated="OnClientNodePopulatedHandler">  
        <Nodes> 
            <telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack"   
                Text="Root RadTreeNode1">  
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack"   
                Text="Root RadTreeNode2">  
            </telerik:RadTreeNode> 
        </Nodes> 
        <CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation> 
 
        <ExpandAnimation Duration="100"></ExpandAnimation> 
    </telerik:RadTreeView> 
    </div> 
    </form> 
</body> 
</html> 

Also, I don't really understand - surely my code was updating the child node about to be added to the parent ie 

e.Node.AllowEdit =

False 'IGNORED

e.Node.Nodes.Add(node))

even though it was running from the NodeExpand. I'm not setting the property on the ParentNode, just the one being added, which is a child. Isn't this just a case of missing functionality in the component - it must be reasonable to set this AllowEdit property serverside before adding the node so that the correct javascript can be sent to the client?

Either way, I can't get this to work, can you?
0
Veselin Vasilev
Telerik team
answered on 24 Jun 2008, 11:50 AM
Hello Phil C,

Let me explain in more detail:

In the NodeExpand event handler, e.Node represents the node that has just been clicked (expanded), let's call it the parent node because we add child nodes to it. This is the purpose of the NodeExpand event - to add child nodes of the expanded node.
What I said in my previous post was that in this event the changes made to the parent node (e.Node) are not persisted, e.g. if you set
  e.Node.AllowEdit = false;
this will not take effect because you are trying to modify the parent node
.
But, you can add child nodes to this parent node. Moreover, all properties that are set for these child nodes will take effect for them, e.g.

    protected void RadTreeView1_NodeExpand(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
    { 
        RadTreeNode node = new RadTreeNode("child " + e.Node.Level.ToString()); 
        node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; 
        //this child node will not be editable 
        node.AllowEdit = false; 
        e.Node.Nodes.Add(node); 
    } 

In the above code the child node will not be editable.

To summarize - in the NodeExpand event you cannot set any properties on the parent node, but you can set all properties to the added children of the parent node.

If you still want to change a property of the parent node - you need to subscribe to the OnClientNodePopulated client-side event and set the properties there as shown in my previous post.

I hope this helps.

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil C
Top achievements
Rank 2
answered on 24 Jun 2008, 03:39 PM
Thanks for the clarification Veskoni, I understand and now realise the issue was that I was using e.Node.AllowEdit = False instead of node.AllowEdit = False .

Still a connected problem though - almost works, this code is simplified and allows editing of even-numbered nodes but not odd-numbered. However this only applies on creation - actually you can go back to node3 after trying node4 and 5 for example and it has become editable!

If you take out the AllowNodeEditing="true" from the treeview declaration then none of the nodes are editable, even though the odd ones are still set as AllowEdit as before!

This seems like a bug - the existing nodes shouldn't have their AllowEdit changed because new nodes are being added?
0
Phil C
Top achievements
Rank 2
answered on 24 Jun 2008, 03:41 PM
Thanks for the clarification Veskoni, I understand and now realise the issue was that I was using e.Node.AllowEdit = False instead of node.AllowEdit = False .

Still a connected problem though - almost works, this code is simplified and allows editing of even-numbered nodes but not odd-numbered. However this only applies on creation - actually you can go back to node3 after trying node4 and 5 for example and it has become editable!

If you take out the AllowNodeEditing="true" from the treeview declaration then none of the nodes are editable, even though the odd ones are still set as AllowEdit as before!

This seems like a bug - the existing nodes shouldn't have their AllowEdit changed because new nodes are being added?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="LODAllowEdit2.aspx.vb" Inherits="RadTreeView_LODAllowEdit2_Default" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
    <asp:ScriptManager ID="ScriptManager1" runat="server"
    </asp:ScriptManager> 
    <div> 
    <!-- OnClientNodeClicking="onClientNodeClicking" OnClientNodePopulated="OnClientNodePopulatedHandler" OnNodeClicked="NodeClicked" removed for clarity of AllowEdit="false" problem --> 
    <telerik:RadTreeView id="RadTreeView1" runat="server" 
        > 
        <Nodes> 
            <telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack"  
                Text="Root RadTreeNode1"
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" ExpandMode="ServerSideCallBack"  
                Text="Root RadTreeNode2"
            </telerik:RadTreeNode> 
        </Nodes> 
        <CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation> 
        <ExpandAnimation Duration="100"></ExpandAnimation> 
    </telerik:RadTreeView> 
    </div> 
    <br /> 
 
    </form> 
</body> 
</html> 

Imports Telerik.Web.UI 
Imports System.Web.UI.HtmlControls 
 
Partial Class RadTreeView_LODAllowEdit2_Default 
    Inherits System.Web.UI.Page 
 
    Protected Sub RadTreeView1_NodeExpand(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeExpand 
        Dim node As RadTreeNode = New RadTreeNode("node" & e.Node.Level) 
        node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack 
        If e.Node.Level Mod 2 = 0 Then 
            node.AllowEdit = True 
        Else 
            node.AllowEdit = False 
        End If 
        e.Node.Nodes.Add(node) 
    End Sub 
 
    Protected Sub RadTreeView1_NodeEdit(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadTreeNodeEditEventArgs) Handles RadTreeView1.NodeEdit 
        e.Node.Text = e.Text 
    End Sub 
 
    Protected Sub NodeClicked(ByVal sender As ObjectByVal e As RadTreeNodeEventArgs) 'Handles RadTreeView1.NodeClick 
        'Disable Handles as it jams the single click 
    End Sub 
 
End Class 

0
Veselin Vasilev
Telerik team
answered on 27 Jun 2008, 07:49 AM
Hi Phil,

In order to work editing of the nodes - the RadTreeView's property AllowNodeEditing should be set to True. Then you can set explicitly the AllowEdit property of every node if you wish, so some nodes can be edited, other - not.

The example you pasted is working properly. Node0 can be edited, Node1 cannot, Node2 can, Node3 cannot, etc.


Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil C
Top achievements
Rank 2
answered on 27 Jun 2008, 08:30 AM
Yes, newly created ones are alternatively editable or not as set node by node - but only when initially created. However, as stated, if you try to edit the previously created nodes (ie. odd-numbered ones which were set to AllowEdit=false), you can now edit them!!

Did you check this? Because I have just rerun this code and that's exactly what it does.
0
Accepted
Veselin Vasilev
Telerik team
answered on 27 Jun 2008, 08:45 AM
Hi Phil,

This is exactly what I tried, but I could not reproduce the problem.

I am using the latest release - SP2.

Can you try with that please? If it does not help - I recommend that you open a new support ticket and attach a sample project and steps to reproduce the problem.

Thanks

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Phil C
Top achievements
Rank 2
answered on 02 Jul 2008, 02:10 PM
For anyone struggling and still reading, this was a tricky bug, only happens when you actually edit and change text and then go back to a previous AllowEdit=False one, which suddenly becomes editable!

They will be fixing it in future release, meanwhile a workaround. Set an attribute:

node.Attributes("allowEdit") = "true" / "false"

Then on a Page_Load, cycle through the nodes to set accordingly:

For Each node As RadTreeNode In RadTreeView1.GetAllNodes()  
    If node.Attributes("allowEdit") IsNot Nothing Then  
        node.AllowEdit = Convert.ToBoolean(node.Attributes("allowEdit").ToString())  
    End If  
Next  

HTH, Phil
Tags
TreeView
Asked by
Phil C
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Phil C
Top achievements
Rank 2
Share this question
or