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

Adding Custom Attributes at Client

5 Answers 156 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Charlie Bross
Top achievements
Rank 1
Charlie Bross asked on 05 Aug 2008, 01:18 AM
I have read through the documentation concerning the ability to use Custom Attributes from both the client side and the server side. While this is working beautifully when a custom attribute is added at the server side, modified client side, and then re-evaluted at server side. Where I am running into an issue is when I am adding a custom attribute client side, it is not being sent back to the server. Is this a bug, am I missing something, or is it just not designed to do this?

Thanks!

======================================
Code Sample: Click on Node to add Custom Attribute
  Client Side. Click Submit button to see attribute not
  accessible.
======================================
<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e){
        lblClientAttribute.Text = "--";
        if (!Page.IsPostBack)
            RadTreeView1.Nodes[0].Attributes.Add("ServerAttribute", "This is my Server Setting");
        else
            lblClientAttribute.Text = RadTreeView1.Nodes[0].Attributes["ClientAttribute"];    }
</script>
<script type="text/javascript">
    function OnClientNodeClicked(sender, args){
        var node = args.get_node(); alert(node.get_attributes().getAttribute("ServerAttribute"));
        node.get_attributes().setAttribute("ClientAttribute", "This is my Client Attribute");
        alert("Client Attribute Added: " + node.get_attributes().getAttribute("ClientAttribute"));}
</script>
<head runat="server"></head>
<body><form id="form" runat="server">
    <telerik:RadScriptManager runat="server" OutputCompression="AutoDetect"></telerik:RadScriptManager>
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientNodeClicked="OnClientNodeClicked">
        <Nodes><telerik:RadTreeNode runat="server" id="node1" Text="Sample Node"></telerik:RadTreeNode></Nodes>
    </telerik:RadTreeView>
    <br /><br />
    <asp:Label runat="server" ID="lblClientAttribute"></asp:Label>
    <br /><br />
    <asp:Button runat="server" ID="btnTest" Text="Submit" />
</form></body></html>

5 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 05 Aug 2008, 06:06 AM
Hello Charlie Bross,

You should call the trackChanges() / commitChanges() methods in order to persist any client-side modifications on the server side. More info can be found here.

Best wishes,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Charlie Bross
Top achievements
Rank 1
answered on 05 Aug 2008, 12:11 PM
Thats exactly what I was looking for and the piece that I was missing! Thanks!
0
TriZetto
Top achievements
Rank 1
answered on 11 Sep 2008, 06:26 PM
I am having a similar problem, but i am using RadControls for ASP.NET (Q2 08, not the Prometheus)
The trackChanges and commitChanges are not available to me.
Can you point me in the right direction?
Thanks

0
Robert Bross
Top achievements
Rank 1
answered on 11 Sep 2008, 08:32 PM
 Hi TriZetto,

Are you trying to use this client side or server side. I believe that these properties are client side only. This is how I am using it below...


function

setNodeAttr(ele, key){
    var

tree = $find("tvwControls");
    tree.trackChanges();
    _currentNode.get_attributes().setAttribute(key, ele.value);
    tree.commitChanges();
}


Hope this helps

0
Veselin Vasilev
Telerik team
answered on 12 Sep 2008, 07:31 AM
Hello guys,

TriZetto, the "classic" treeview does not have trackChanges and commitChanges methods. Instead, it has the
UpdateState() method.

You can check this help article for more information:
Telerik RadTreeView Client-Side > The RadTreeView client object


Greetings,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Charlie Bross
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Charlie Bross
Top achievements
Rank 1
TriZetto
Top achievements
Rank 1
Robert Bross
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or