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

How to change the value of Custom Attribute on Client side and Access it on the server side

1 Answer 122 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gijsbertus Marinus De Boer
Top achievements
Rank 1
Gijsbertus Marinus De Boer asked on 22 Jul 2010, 08:11 AM
Hi All,
    Is it possible to change the value of custom attribute on the client side then access it on the server side?
Because I'm trying to change some value of custom attribute on the client side and try to get it during post back, but the value that I get is still the initial value when i created the attribute.

below is my sample code
client script

<script type="text/javascript">
   var activenode = null;
   function $(id){return document.getElementById(id);}
   function AppySetting(){
      if (activenode!=null){
          activenode.setAttribute('AllowAdd'   ,(($('AllowAdd'   ).checked)? 'True':'False'));
          activenode.setAttribute('AllowEdit'  ,(($('AllowEdit'  ).checked)? 'True':'False'));
          activenode.setAttribute('AllowDelete',(($('AllowDelete').checked)? 'True':'False'));
      }
   }
   function OnClientNodeClicked(sender, args)
   {  
        activenode = args.get_node().get_attributes();
        $('AllowAdd'   ).checked = activenode.getAttribute('AllowAdd'   )=='True';
        $('AllowEdit'  ).checked = activenode.getAttribute('AllowEdit'  )=='True';
        $('AllowDelete').checked = activenode.getAttribute('AllowDelete')=='True';
   }
 </script>

server code :
aspx page
<telerik:RadTreeView id="RadTreeViewBackOffice" runat="server" CheckBoxes="True" TriStateCheckBoxes="true" CheckChildNodes="true" OnNodeDataBound="OnNodeDataBound"  OnClientNodeClicked="OnClientNodeClicked" OnClientNodeChecking="OnClientNodeClicked" />

code behind :

 

protected

 

void OnNodeDataBound(object sender, RadTreeNodeEventArgs e ){

           e.Node.Attributes.Add("AllowAdd" ,"True");         

           e.Node.Attributes.Add("AllowEdit" ,"True");

           e.Node.Attributes.Add("AllowDelete" ,"True");

protected void OnClick(object sender, EventArgs e )

 {
  foreach(RadTreeNode Node in RadTreeViewBackOffice.CheckedNodes){
         Response.Write(Node.Attributes["AllowAdd"]);
  }

}
when I call the method Onclick the value of the Attribute is still the same ("True")  even i set "False" in the client side.
regards

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Tsenkov
Telerik team
answered on 23 Jul 2010, 03:57 PM
Hello Gijsbertus Marinus De Boer,

Basically, you need to place the changes over the existing nodes between treeView.trackChanges() and treeView.commitChanges in order these changes to be included in the viewState.


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Gijsbertus Marinus De Boer
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or