Loading user control dynamically looses data
Posted
by user228777
on Stack Overflow
See other posts from Stack Overflow
or by user228777
Published on 2010-04-22T13:19:30Z
Indexed on
2010/04/22
13:23 UTC
Read the original article
Hit count: 228
vb.net
|usercontrol
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.
© Stack Overflow or respective owner