Dynamic controls and viewstate

G

Guest

Hello All,

I am trying to add dynamic controls onto my page and here is how I am doing
that.

I have a page which has a button called as "AddMoreControls" and in this
button's event handler I am creating controls dynamically and adding them to
a panel on the page. For example, if the button is clicked once, the page is
posted back and the controls are added properly. However, if I click the
"AddMoreControls" for the second time the previously added controls are gone.
Does anyone know why the system is behaving in this way?

I understand that the static controls are created during init() method and
their viewstate is loaded properly. How does this work for dynamic controls?

Thanks!!
 
T

Teemu Keiski

Hi,

dynamic controls would need to be created on every request. E.g if you
create them initially in a postback event such as button click, you'd need
to recreate them on next Page loading so that they'd exist in the Controls
collection. ViewState would work when you'd have dynamic control
instantiation in order.

Here's a few links I've blogged for the reference how to work with Dynamic
controls
http://aspadvice.com/blogs/joteke/archive/2006/01/06/14568.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top