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

Problem with treeview having template column loosing state after postback

5 Answers 32 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
kamii47
Top achievements
Rank 1
kamii47 asked on 27 Sep 2013, 11:35 AM
I have a treeview which i have used extended template 
public class MyNodeTemplate : ITemplate
   {
       public string StrText { get; set; }
 
       public void InstantiateIn(Control container)
       {
           var txt = new TextBox();
           if (!String.IsNullOrEmpty(StrText))
           {
               txt.Width = new Unit(StrText.Length, UnitType.Em);
               txt.Text = StrText;
           }
           container.Controls.Add(txt);
       }
   }

I am binding it on some dropdownlist selected index change event

if (ddlTemplateSource.SelectedValue != "0")
            {
                TreeView1.Nodes.Clear();
 
 
                var lstSections =  SourceSectionBll.GetInstance.GetSourceSectionsByTemplateSourceId(Int32.Parse(ddlTemplateSource.SelectedValue));
 
 
                if (lstSections != null)
                {
                       if (obj.LstSimpleFieldSectionMappers != null &&  )
                        {
                            var tNodeChildSimpleFields = new RadTreeNode("Simple_fields_Control");
 
                            foreach (var objSimplefield in    obj.LstSimpleFields)
                            {
                                var tNodeChildSimpleFieldTextEntry = new RadTreeNode(objSimplefield.FieldName);
                                var tSimpleFiledLeafNode = new RadTreeNode {Expanded = true};
 
                                var objtemplate = new MyNodeTemplate {StrText = objSimplefield.FieldCode};
                                objtemplate.InstantiateIn(tSimpleFiledLeafNode);
                                tNodeChildSimpleFieldTextEntry.Nodes.Add(tSimpleFiledLeafNode);
                                tNodeChildSimpleFields.Nodes.Add(tNodeChildSimpleFieldTextEntry);
                            }
                            tNode.Nodes.Add(tNodeChildSimpleFields);
                        }                     
                        TreeView1.Nodes.Add(tNode);
                }               
            }

Problem is that treeview loses text inside the textbox when there is a button click event is triggerd
Anyway i can intact the data in the text box of MyNodeTemplate template?


5 Answers, 1 is accepted

Sort by
0
kamii47
Top achievements
Rank 1
answered on 30 Sep 2013, 11:22 AM
could any body help me in it?
I am seen there is not much replies in telerik treeview forums
0
Hristo Valyavicharski
Telerik team
answered on 02 Oct 2013, 11:15 AM
Hi,

Probably the template is recreated every time you cause postback. That's why its value is lost. You may try to store TextBox's value in session for example and restore it after the template is recreated. 

Take a look at the attached sample, it shows how to persist values over the postbacks.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
kamii47
Top achievements
Rank 1
answered on 02 Oct 2013, 12:23 PM
Can you help me in accordance with the sample to persist data.I wanted to avoid the session sort of saving in my scenario
Not able to map the sample with my implementation to persist the textbox data
0
Hristo Valyavicharski
Telerik team
answered on 07 Oct 2013, 01:25 PM
Hi,

As far as I see from the pasted code you are using the standard asp.net tree view control and the standard asp.net dropdown list. Am I right?  Please open a support ticket and attach a fully runnable sample as describe in details what is the issue you have experienced with the Telerik controls. Once we manage to reproduce the observed behavior locally, we would be able to look for a solution.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
kamii47
Top achievements
Rank 1
answered on 07 Oct 2013, 04:21 PM
I am using the telerik tree view.Don't know if asp.net treeview supports Itemplate and instantiating .
I will show you code tomorrow for confirmation
Tags
TreeView
Asked by
kamii47
Top achievements
Rank 1
Answers by
kamii47
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or