views:

250

answers:

1

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.

A: 

If data is posted, you can get it from Request.Form[control.UniqueID] , but don't use viewstate possibilities hehe if control added dynamically.

TriLLi
What I am trying to do is show all details when edit button on user control is clicked ( whic are on asp Panel) on first load these are populated. But when I make visible on edit click they are not populated any more. But By default if I keep panel visible I do see all controls populated. It means that post back sent by edit button is loosing the data. Which it should not. I don't understand what's happening.
Basically if you need to start editing control populate fields by assigning them value from Request.Form | That means if you have control txtName you can populate from Form like this txtName.Text = Request.Form[txtName.UniqueID].ToString(); Basically if you are adding controls dynamically than there is no view state for that control, but you can also access existing view state using ViewState["name"]
TriLLi
how to populate those controls is not an issue here. I populate them on page load in INVISIBLE panel. When I make PANEL VISIBLE by button click. controls should be just visible with prepopulated values on page load. I am just making panel visible nothing else. But all text boxes come empty. Why should I repopulate them? I know with post back page is re written compeltly with values saves in viewsatate.