Controlling dynamic contols

A

Assaf

I'm looking for the 'right way' to save the state of dynamically created
custom controls. Here's the scenario:

Multiple instances of myCustomControl are added to a page programmatically
at run time. Because they are dynamic, I have to recreate all
myCustomControl's on every postback. For now, I am saving all properties of
myCustomControl's to the ViewState in a serializable 'descriptor' class and
cycle through at page_load. That works fine but it seems like duplicate
effort because every property of every instance has to be written to the
control AND the serializable class. Also, the control is about to grow
complex soon and synchronizing it with a descriptor class will become
cumbersome.

Interested in what others have done in this situation. Has anyone attempted
implementing ISerializable on a custom control and stuffing it into a
ViewState?

Thanks for any advice.

- Assaf
 
A

Assaf

Victor,

I looked through the DynamicControlsPlaceholder sample and the help file.
Having a hard time following the logic. Do you have a write-up or can you
outline the solution?

Thanks.

Assaf


Victor Garcia Aprea said:
Hi Assaf,

This[1] is one way of handing what you're describing,

Also take a look at my posts[2] about viewstate, where I gave low-level
details about the viewstate serializer.

[1] http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx
[2] http://weblogs.asp.net/vga

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx


Assaf said:
I'm looking for the 'right way' to save the state of dynamically created
custom controls. Here's the scenario:

Multiple instances of myCustomControl are added to a page programmatically
at run time. Because they are dynamic, I have to recreate all
myCustomControl's on every postback. For now, I am saving all properties of
myCustomControl's to the ViewState in a serializable 'descriptor' class and
cycle through at page_load. That works fine but it seems like duplicate
effort because every property of every instance has to be written to the
control AND the serializable class. Also, the control is about to grow
complex soon and synchronizing it with a descriptor class will become
cumbersome.

Interested in what others have done in this situation. Has anyone attempted
implementing ISerializable on a custom control and stuffing it into a
ViewState?

Thanks for any advice.

- Assaf
 
M

Mircea Pleteriu

Hi,



I have a web composite control which consists in a DataGrid control for
beginning.

The data grid is created dynamically by the CreateChildContols method.



When my custom control is hosted by the aspx page I can see that the inner
grid is not persisted.



How can I use your example about persisting control to implement the
behavior I need for my control?



Best regards,

Mircea





Victor Garcia Aprea said:
Hi Assaf,

This[1] is one way of handing what you're describing,

Also take a look at my posts[2] about viewstate, where I gave low-level
details about the viewstate serializer.

[1] http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx
[2] http://weblogs.asp.net/vga

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx


Assaf said:
I'm looking for the 'right way' to save the state of dynamically created
custom controls. Here's the scenario:

Multiple instances of myCustomControl are added to a page programmatically
at run time. Because they are dynamic, I have to recreate all
myCustomControl's on every postback. For now, I am saving all properties of
myCustomControl's to the ViewState in a serializable 'descriptor' class and
cycle through at page_load. That works fine but it seems like duplicate
effort because every property of every instance has to be written to the
control AND the serializable class. Also, the control is about to grow
complex soon and synchronizing it with a descriptor class will become
cumbersome.

Interested in what others have done in this situation. Has anyone attempted
implementing ISerializable on a custom control and stuffing it into a
ViewState?

Thanks for any advice.

- Assaf
 

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

No members online now.

Forum statistics

Threads
473,985
Messages
2,570,200
Members
46,768
Latest member
BerryMarga

Latest Threads

Top