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

Add User Control to RadPane in code behind not persisting

1 Answer 108 Views
Splitter
This is a migrated thread and some comments may be shown as answers.
M Mayo
Top achievements
Rank 1
M Mayo asked on 02 Oct 2008, 06:34 PM
I am trying to develop a page with a rad tree within the left pane of a splitter and when a node is clicked I want to add a control (ascx) programatically to the right pane. It works, but when the edit button is clicked in the right pane's control, the postback happens, but the dynamically loaded control that was in the right pane does not get the postback.

The enable view state is set to true in the splitter, but nothing happens. I have examined the controls collection on the post back in question and the control I am loading dynamically is not there.

Here is the page with the splitter:

public partial class components_NorViewer : System.Web.UI.UserControl  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!Page.IsPostBack)  
        {  
            string rootFolder = Server.MapPath("~/NORs");  
 
            RadTreeNode rootNode = new RadTreeNode(Path.GetFileName(rootFolder));  
            rootNode.ImageUrl = "~/images/folder.gif";  
            rootNode.Expanded = true;  
            RadTreeView1.Nodes.Add(rootNode);  
            BindTreeToDirectory(rootFolder, rootNode);  
        }         
    }  
    private void BindTreeToDirectory(string dirPath, RadTreeNode parentNode)  
    {  
        string[] directories = Directory.GetDirectories(dirPath);  
        foreach (string directory in directories)  
        {  
            RadTreeNode node = new RadTreeNode(Path.GetFileName(directory));  
            node.ImageUrl = "~/images/folder.gif";  
            parentNode.Nodes.Add(node);  
            BindTreeToDirectory(directory, node);  
        }  
 
        string[] files = Directory.GetFiles(dirPath);  
        foreach (string file in files)  
        {  
            RadTreeNode node = new RadTreeNode(Path.GetFileNameWithoutExtension(file));  
            node.ImageUrl = "~/images/new.gif";  
            node.ToolTip = "Click to Load Groups of this NOR";  
            parentNode.Nodes.Add(node);  
        }  
    }  
    protected void NodeClick(object sender, RadTreeNodeEventArgs e)  
    {  
        switch (e.Node.Level)  
        {  
            case 1:  
                components_NorDetail uc1 = (components_NorDetail) Page.LoadControl("~/components/NorDetail.ascx");  
                uc1.FileName = "~/NORs/" + e.Node.Text + ".xml";  
                RadPane2.Controls.Add(uc1);                 
                BuildNorSectionNodes(e.Node.Text, e.Node);  
                break;  
            case 2:  
                Control uc = Page.LoadControl("~/components/NorSection.ascx");  
                RadPane2.Controls.Add(uc);  
                break;  
        }  
    }  
    private void BuildNorSectionNodes(string strfile, RadTreeNode parentNode)  
    {  
        DataSet ds = new DataSet();  
        ds.ReadXml(Server.MapPath("~/NORs/" + strfile+".xml"));  
        foreach (DataRow dr in ds.Tables["sectiongroup"].Rows)  
        {  
            RadTreeNode node = new RadTreeNode(dr["sectiongroupnumber"].ToString()+" "+dr["sectiongrouptext"].ToString());  
            node.ImageUrl = "~/images/new.gif";  
            node.ToolTip = "Click to Load Sections of this Group";  
            node.Expanded = true;  
            parentNode.Nodes.Add(node);  
        }  
        parentNode.Expanded = true;  
     }  

Here is the Control (ascx) in question:

public partial class components_NorDetail : System.Web.UI.UserControl  
{  
    private string strFileName;  
    public string FileName  
    {  
        set { strFileName = value; }  
        get { return this.strFileName; }  
    }  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        DataSet ds = new DataSet();  
        ds.ReadXml(Server.MapPath(FileName));  
        litDate.Text = ds.Tables["NOR"].Rows[0]["date"].ToString();  
        litDesc.Text = ds.Tables["NOR"].Rows[0]["desc"].ToString();  
        litTitle.Text = ds.Tables["NOR"].Rows[0]["title"].ToString();  
        litUpdated.Text = ds.Tables["NOR"].Rows[0]["updated"].ToString();  
    }  
    protected void lkbEdit_Click(object sender, EventArgs e)  
    {  
        string strtest = string.Empty;  
    }  

The string in the lkbEdit_Click method is where I would expect that the postback in question would stop on a breakpoint, when I set one there. It does not. Rad Pane 2 is the pane I am having the issue with.

Thanks!!

1 Answer, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 03 Oct 2008, 11:25 AM
Hi M Mayo,

As far as I understood your scenario, the problem is not related to the RadSplitter control but to general ASP.NET knowledge and of dynamic creation and addition of controls. Please, note that ASP.NET do not recreate the dynamic controls and you should recreate them in a suitable event according to your needs.

In order to test this by yourself, please remove the splitter from your application and add the control to a standard asp panel - it should not be persisted after a postback. In case your scenario works with the panel and it does not work with the splitter, please open a new support ticket, send me the correctly working project which does not use splitter but panel and I will modify it for you in order to use a splitter instead of panel.

Best wishes,
Svetlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Splitter
Asked by
M Mayo
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Share this question
or