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

Controls disappear

1 Answer 123 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michał
Top achievements
Rank 1
Michał asked on 02 Aug 2008, 06:36 AM

Hello,
I have a very big problem. I won`t put the Controls in Tree View.
When I put the Controls everything is ok control is on the Tree View.

But when I won`t read data from my control my control I disappear from tree view.

This is my simple Code :

ASPX :

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">

    </asp:ScriptManager>

   

    <div>

        <telerik:RadTreeView ID="RadTreeView1" runat="server">

        </telerik:RadTreeView>

        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

        <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />

    </div>

    <p>

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </p>

    </form>

</body>

</html>

CS :

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

            if (!IsPostBack)

            {

                  TextBox txt = new TextBox();

                  Telerik.Web.UI.RadTreeNode tn = new Telerik.Web.UI.RadTreeNode("1");

                  txt.ID = "fff";

                  tn.Controls.Add(txt);

                  RadTreeView1.Nodes.Add(tn);

            }

    }

      protected void Button1_Click(object sender, EventArgs e)

      {

            Label1.Text = ((TextBox)RadTreeView1.Nodes[0].FindControl("fff")).Text;

      }

      protected void Button2_Click(object sender, EventArgs e)

      {

            Label1.Text = ((TextBox)RadTreeView1.Nodes[0].Controls[0]).Text;

      }

}

Please Help My. Thank so much

 

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 Aug 2008, 07:57 AM
Hi MichaƂ,

Controls added dynamically to a tree node need to be recreated after postback. Otherwise they will disappear as RadTreeView cannot recreate custom controls after postback. The same behavior is present with the built-in Panel and Placeholder controls. Here is how your modified code should look like:

protected void Page_Load(object sender, EventArgs e) 
    if (!IsPostBack) 
    { 
        Telerik.Web.UI.RadTreeNode tn = new Telerik.Web.UI.RadTreeNode("1"); 
        RadTreeView1.Nodes.Add(tn); 
    } 
    TextBox txt = new TextBox(); 
    txt.ID = "fff"
    RadTreeView1.Nodes[0].Controls.Add(txt); 
 


Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Michał
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or