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

[Solved] Prevent client side selection

2 Answers 148 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Darren Hall
Top achievements
Rank 1
Darren Hall asked on 05 Mar 2008, 02:47 AM
Is there a way to prevent client side selection so that selection only occurs when I set it in the code behind at the server?  All my nodes postback and I don't want the node that has been clicked on to appear selected before the postback.  The reason is because I am highlighting the path to the node on postback and the selection path momentarily disappears when the new node is clicked on the client.

Thanks,

Darren.

2 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 05 Mar 2008, 07:08 AM
Hello Darren,

Please find below a sample code snippet that shows the needed approach.

ASPX:
<form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
 
    <script type="text/javascript">  
        function ClearSelection(sender, eventArgs)  
        {  
            eventArgs._node.set_selected(false);  
        }  
    </script> 
 
    <telerik:RadTreeView ID="RadTreeView1" runat="server" LoadingStatusPosition="BeforeNodeText" Skin="Web20" OnClientNodeClicked="ClearSelection" OnNodeClick="RadTreeView1_NodeClick1">  
        <Nodes> 
            <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="Root RadTreeNode1">  
                <Nodes> 
                    <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="Child RadTreeNode 1">  
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="Child RadTreeNode 2">  
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" ExpandMode="ClientSide" Text="Child RadTreeNode 3">  
                    </telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeNode> 
        </Nodes> 
        <CollapseAnimation Duration="100" Type="OutQuint" /> 
        <ExpandAnimation Duration="100" Type="OutQuart" /> 
    </telerik:RadTreeView> 
    <asp:Label ID="Label1" runat="server" Text="Label" Width="224px"></asp:Label> 
</form> 

Code-behind:
protected void RadTreeView1_NodeClick1(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)  
{  
    Label1.Text = e.Node.Text;  


All the best,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Darren Hall
Top achievements
Rank 1
answered on 05 Mar 2008, 12:36 PM
Oops, my mistake, what I actually wanted was that the current path be highlighted.  Anyway, thanks to your showing me the way, this is what I did.

        <script type="text/javascript">     
        function SetPath(sender, eventArgs)     
        {     
        var currentObject = eventArgs._node.get_parent();  
                while (currentObject.get_parent() != null)  
                    {  
                    currentObject.set_selected(true);  
                    currentObject = currentObject.get_parent();  
                    }  
        }     
        </script> 

Where SetPath is called from the OnClientNodeClicked event of RadTreeView.

The support here really is excellent, thanks!

Darren.
Tags
TreeView
Asked by
Darren Hall
Top achievements
Rank 1
Answers by
Paul
Telerik team
Darren Hall
Top achievements
Rank 1
Share this question
or