Add a UserControl to an ArrayList

S

s.bussing

Hi, does anyone have an Idea if it's possible to add a UserControl
(containing serveral other controls like textboxes and/or
dropdownlists) to an ArrayList?

If I just put [Serializable] at the top of the class of the
UserControl, it does not make a difference, I keep getting the error:


The type 'ASP.UCXXXXXXX_ascx' must be marked as Serializable or have a
TypeConverter other than ReferenceConverter to be put in viewstate.

Also adding the interface ISerializable doesn't work. Maybe it's not
possible at all.

Anyone?

Thanks
 
K

Karl Seguin [MVP]

You can't do that. You can't just serialize an entire user control ito
viewstate.

Normally, people simply store the path to the user control in the viewstate
and reload them on postback

foreach(string controlPath in (ArrayList)ViewState["ControlsToReload"])
{
SomePlaceHolder.Controls.Add(Page.LoadControl(controlPath));
}

Karl
 
S

s.bussing

Thanks Karl, I was afraid this would be the answer. To bad.

@Jason, I use a kind of construction Karl was refering to. What I do
is, I build an ArraList, in this list I add the controls ClientID. On
postback I recreate the control based on a foreach of all elements in
the ArrayList. This works fine. But yesterday I wanted to try to
changes records I use the UserControls with. That part I didn't figure
out yet, but I'm close. If you're intrested I could send you my code.
It's kind of difficult because I use nested controls until three levels
deep. Just send me you emailadress

Thansk for replying
 

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

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top