Adding a Dynamic User Control from the Base Page Class (and retaining it on Postback?)

D

David Bowey

Hi There!

As the subject says, I need to add a user control dynamically (using
LoadControl function) to the derieved page from the base Page class and I
want the added contol to be retained on PostBack as well as retain its'
state (such as properties).

How do I acoomplish this?

Thank you all in advance.
Dave
 
R

recoil

If possible create the control in the OnInit each time. Make sure you
give it a Unique ID. If you do both of these I believe the ViewState
should be handled for you automatically
 
N

Nick Stansbury

I think it is also pretty important that you add the control in to the
controls collection before ammending any of its properties:

i.e.
dim txtAAA as textbox
txtAAA = new textbox
txtAAA.id = "txtAAA"
txtAAA.text = "BBB" '<-- I don't think that this text property would be
tracked by the viewstate
me.controls.add(txtAAA)
txtAAA.text = "AAA" <-- whereas this one would....
 

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
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top