By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

Dynamic controls and viewstate

P: n/a
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!!

Mar 17 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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/ar.../06/14568.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
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!!

Mar 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.