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

Loading userControl dynamically loosing data.

4 Answers 284 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
A K
Top achievements
Rank 1
A K asked on 22 Apr 2010, 02:18 PM

I have a created a user control. This user control I dynamically load on a page inside Telerik  Panelbar control. I have done all necessary coding to save the viewstate and load this dynamically created usercontrol every time page loads.

On this User control I have a asp panel. By default this panel is invisible. When user clicks a button on this user control panel is made visible.  On page load of this user control I populate all the controls on this panel.

Everything works fine if I don’t  load this use control dynamically but when I load this user control dynamically  and if I make panel visible by default then only all fields on the panel are populated. But if I make by default invisible and on button click make panel visible none of the text boxes or comboboxes are populated.

I populate comboboxes on page load of the userControl but inbetween  postbacks all the comboboxes on the user control loose data.

ON the parent page I am saving the viewstate

This is my code on parent page to dynamically load userControl  ( which has panel on it)

Dim ucPiggyBank As SubscriberSetupPages_UserControls_PiggyBank = CType(LoadControl("~/SubscriberSetupPages/UserControls/PiggyBank.ascx"), SubscriberSetupPages_UserControls_PiggyBank)

            With ucPiggyBank

                  .PiggyBankID = account.Id

                  .ID = account.Id.ToString

                  'Setting up following 3 properties here to avoid database trips

                  .PiggyBankEligibleAccounts = piggyBankEligibleAccountCollection

                  .MemorizedNames = memorizednames

                  .Period = period

            End With   

            radPanelNewChild.Controls.Add(ucPiggyBank)

            radPanelNew.Items.Add(radPanelNewChild)

            radPanelNew.Expanded = True

‘this is the Panel item on parent page of Telerik Panelbar control.

Dim radPanelPiggyBank As RadPanelItem = DirectCast(pnlbarPiggyBank.FindItemByValue("TestItem"), RadPanelItem)

            With radPanelPiggyBank

                  .Items.Add(radPanelNew)

                  .DataBind()

            End With

‘I am doing everything for saving viewstate on parent control

This is the code on page load of userControl

      If Not IsPostBack Then

 

                 

 

 

                 

                  If m_PiggyBankID <> Guid.Empty Then

                        'Load data

                        Call GetPiggyBankDetails()

                  End If

 

I have a edit button on the user control which makes panel visible.  It makes panel visible but with no data.

Can you please tell me what’s happening?

Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
kachy
Top achievements
Rank 1
answered on 19 Aug 2010, 08:11 PM
Hi,

Were you able to resolve the problem. I am also having the same problem and also I am not able to handle the user control event on the parent page if I add the control dynamically.

Thanks.
0
Nikolay Tsenkov
Telerik team
answered on 23 Aug 2010, 02:14 PM
Hi kachy,

Could you, please, describe the problem you experience in a bit more detail?
Also you can post an aspx page and a code-behind reproducing so we can test and resolve the issue you currently are having with RadPanelBar.
Thanks!

Hope that soon we will get to the bottom of this!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Fayaz
Top achievements
Rank 1
answered on 05 May 2013, 12:43 PM
protected void Page_Load(object sender, EventArgs e)
{
      if (!Page.IsPostBack)
        {
           FillRegionalWorkflow();
         }
}
// Loading the UserControl
  private void FillRegionalWorkflow()
    {
        RegionalWorkflow cRegionalWorkflow;
        RadPanelItem panelItem=null;
        GSPORegionalWorkFlow grw = new GSPORegionalWorkFlow();
        gspoRwfionalWorkflowBO = new GSPORegionalWorkflowBO();
        // This is to split the RegionIDS
        string[] RegionIDs = null;
        int[] regionid=new int[6];
        int count = 0;
        
 
        if (this.UserContext.RegionIDs.Length > 0)
        {
            RegionIDs = this.UserContext.RegionIDs.Split(',');
        }
 
        // This is to Get The RegionIDs
        if (RegionIDs.Length > 0)
        {
            for (int i = 0; i < RegionIDs.Length; i++)
            {
                regionid[i] = Int32.Parse(RegionIDs[i]);
            }
        }
 
        foreach (DomainCode dc in listClarifyRegions)
        {
 
            grw = gspoRwfionalWorkflowBO.GetRegionalWorkflowByRegion(policyId, dc.ShortCode);
            if (grw != null)
            {
 
                // If the User is GETSSET then allows editing to the GSPO Page
                // Else check if the User is GSPO an dit has some RegionIDs then he will
                // be able to edit that RegionIds else It will be ReadOnly
                #region
 
                if (this.UserContext.UserRoles == "rl_GetSSET")
                {
 
                    cRegionalWorkflow = (RegionalWorkflow)Page.LoadControl("~/UserControl/RegionalWorkflow.ascx");
                    cRegionalWorkflow.EnableViewState = true;
                    cRegionalWorkflow.ID = "MyControl" + count;
                    cRegionalWorkflow.PolicyID = policyId;
                    cRegionalWorkflow.UserContext = this.UserContext;
                    cRegionalWorkflow.GSPORegionalWorlflow = grw;
                    cRegionalWorkflow.Region = dc.CodeValue;
                    panelItem = new RadPanelItem(dc.CodeValue);
                    panelItem.Controls.Add(cRegionalWorkflow);
                    GSPOPanelBar.Items[0].Items.Add(panelItem);
 
                }
                else
                {
                    for (int i = 0; i < RegionIDs.Length; i++)
                    {
                        if (regionid[i] == dc.CodeID)
                        {
                            //regionworkflow
                            cRegionalWorkflow = (RegionalWorkflow)Page.LoadControl("~/UserControl/RegionalWorkflow.ascx");
                            cRegionalWorkflow.EnableViewState = true;
                            cRegionalWorkflow.ID = "MyControl" + count;
                            cRegionalWorkflow.PolicyID = policyId;
                            cRegionalWorkflow.UserContext = this.UserContext;
                            cRegionalWorkflow.GSPORegionalWorlflow = grw;
                            cRegionalWorkflow.Region = dc.CodeValue;
                            panelItem = new RadPanelItem(dc.CodeValue);
                            panelItem.Controls.Add(cRegionalWorkflow);
                            GSPOPanelBar.Items[0].Items.Add(panelItem);
                        }
                    }
                }
                count++;
                #endregion
 
 
 
            }
        }
 
        CustomContentTemplate template = new CustomContentTemplate();
        foreach (Telerik.Web.UI.RadPanelItem item in GSPOPanelBar.Items[0].Items)
        {
            item.ContentTemplate = new CustomContentTemplate();
            template.InstantiateIn(item);
        }
    }
 
// Here I am saving but my Panelbar is showing Null
 protected void btnSave_Click(object sender, EventArgs e)
    {
   RadPanelItem item = GSPOPanelBar.Items[0];
      
    }
Hi Team,

I Have a RadPanelBar and Inside That I have 3 RadPanelItems in my .aspx. And in the .cs I am adding same Usercontrol upto 5 times inside the Dynamically Created Radpanel and these radpanelitems are  Dynamically added to to the 1st RadpanelItem of the RadpanelBar.
I am able to load the Data into that radpanel. But in the aspx when I am clicking save the page is getting refresh and I am not able to save my dynamically loaded usercontrol data.Can any one please help me out in saving the Data from the User Control.Below is my code of .aspx and .cs ( In Usercontrol I have many Editable controls like textbox,dropdownlist etc.)

.aspx
<telerik:RadPanelBar runat="server" ID="GSPOPanelBar" ExpandMode="MultipleExpandedItems" EnableViewState="true"
                                                                    Width="100%" Skin="Outlook" Height="100%">
 <Items>
<telerik:RadPanelItem Text="Regional Workflow" Selected="true" CssClass="rootItem"                                            SelectedImageUrl="~/images/AccordionExpandW.png" ImageUrl="~/images/AccordionExpandW.png" ImagePosition="Left" ExpandedImageUrl="~/images/AccordionCollapseW.png"
</telerik:RadPanelItem>
 <telerik:RadPanelItem Text="Global Localization Regions" Selected="true" CssClass="rootItem"
 SelectedImageUrl="~/images/AccordionExpandW.png" ImageUrl="~/images/AccordionExpandW.png" ImagePosition="Left" ExpandedImageUrl="~/images/AccordionCollapseW.png">   
</telerik:RadPanelItem>
<telerik:RadPanelItem Text="Regional Support Delivery" Selected="true" CssClass="rootItem"
SelectedImageUrl="~/images/AccordionExpandW.png" ImageUrl="~/images/AccordionExpandW.png" ImagePosition="Left"                                  ExpandedImageUrl="~/images/AccordionCollapseW.png">                                                                           
</telerik:RadPanelItem>
</Items>
</telerik:RadPanelBar>



.cs

In Page Load

0
Boyan Dimitrov
Telerik team
answered on 09 May 2013, 07:09 AM
Hello,

I would suggest loading your user control in the Page_Init instead of Page_Load event handler in order to persist that user control on the page after a post back. Please find a sample code snippet below for reference:
//code behind
protected void Page_Init(object sender, EventArgs e) {
        FillRegionalWorkflow();
    }


Regards,
Boyan Dimitrov
the Telerik team
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 their blog feed now.
Tags
PanelBar
Asked by
A K
Top achievements
Rank 1
Answers by
kachy
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Fayaz
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or