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

Dynamic added usercontrol added to RadPageView are lost

2 Answers 90 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 29 Mar 2011, 12:24 PM
Hello,

I'm trying to dynamiccly add usercontrols to my RadPageView. See exmaple

ASCX
 <telerik:RadTabStrip ID="tabstripContactPerson" runat="server" MultiPageID="mpContactPersonen"
                SelectedIndex="0">
</telerik:RadTabStrip>
<telerik:RadMultiPage ID="mpContactPersonen" runat="server" SelectedIndex="0" CssClass="multipagecontainer">
</telerik:RadMultiPage>

CODEBEHIND
List<WS_RetailerPerson> personen = oRetailer.WS_RetailerPerson.ToList();
  
 foreach (WS_RetailerPerson item in personen)
 {
      using (RadTab tab = new RadTab())
      {
            tab.Text = item.WS_Person.FullName;
            tabstripContactPerson.Tabs.Add(tab);           
      }          
            
      using (RadPageView pageView = new RadPageView())
      {
                PersonEditControl ucPersonEdit = (PersonEditControl)LoadControl(PERSONEDITCONTROL_PATH);
 
                using (DynamicControlsPlaceholder phDynamic = new DynamicControlsPlaceholder())
                {
                       ucPersonEdit.ID = "ucPersonEdit" + item.PersonId.ToString();
                       ucPersonEdit.PersonId = item.PersonId;                  
                       pageView.Controls.Add(ucPersonEdit);
 
                       mpContactPersonen.PageViews.Add(pageView);                                      
                }
            }
        }
}


This works fine but then I want to call the save-methods on each individuel loaded usercontrol in the RadPageViews.

foreach (RadPageView pageView in mpContactPersonen.PageViews)
        {
            foreach (PersonEditControl ucPersonEdit in pageView.Controls)
            {
                ucPersonEdit.Save();
            }
        }

The problem is that it can find the PageView controls in RadPageView but each pageView.Cotrols is empty. It loses my dynamic add usercontrols.

I hope someone can help me out.

Thanks in advance.

Kind regards Patrick

2 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 29 Mar 2011, 01:44 PM
Hello Patrick,

If your adding the controls dynamically, you need to always add them on every postback.

I hope that helps.
0
Patrick
Top achievements
Rank 1
answered on 29 Mar 2011, 01:55 PM
Thx for the quick answer but unfortunately this doesn't help me any further. The problem is that I will make some changes to the fields of the dynamacly loaded usercontrols and then save it to a database.

Is there any workaround to accomplish this.

Thx
Tags
TabStrip
Asked by
Patrick
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Patrick
Top achievements
Rank 1
Share this question
or