Problem with treeview having template column loosing state after postback

6 posts, 0 answers
  1. kamii47
    kamii47 avatar
    31 posts
    Member since:
    Mar 2007

    Posted 27 Sep 2013 Link to this post

    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?


  2. kamii47
    kamii47 avatar
    31 posts
    Member since:
    Mar 2007

    Posted 30 Sep 2013 Link to this post

    could any body help me in it?
    I am seen there is not much replies in telerik treeview forums
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 02 Oct 2013 Link to this post

    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.
  5. kamii47
    kamii47 avatar
    31 posts
    Member since:
    Mar 2007

    Posted 02 Oct 2013 Link to this post

    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
  6. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 07 Oct 2013 Link to this post

    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.
  7. kamii47
    kamii47 avatar
    31 posts
    Member since:
    Mar 2007

    Posted 07 Oct 2013 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017