Avatar of hedgedevelopers
hedgedevelopers asked on

Custom WebControl and State Managent of Dymanicly Added Controls

I want to build a custom server control (WebControl) that has a collection of business objects (Investors) as a public property. What I want to have happen is on the page level I set the collection equal to a collection retrieved from the database and then I call a public function (Build) on the user control.

When Build executes it iterates through the collection of Investors and adds textbox controls to the Controls collection. My problem is is that I keep losing these controls on postback. I need to have these controls and their values be maintained across postbacks and I can't figure out how to do this with dynamically added controls NOT templated controls.
.NET ProgrammingASP.NETC#

Avatar of undefined
Last Comment
Joel Coehoorn

8/22/2022 - Mon
Joel Coehoorn

You need to add the controls to the form earlier in the page's lifecycle: Init or Pre-Init.

But I set the collection property of the control on page_load.
Joel Coehoorn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy