Add a UserControl to an ArrayList

  • Thread starter Thread starter s.bussing
  • Start date Start date
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
 
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
 
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
 
Back
Top