user2547415
user2547415

Reputation: 1

List in viewstate not marked as serializable

I am making a control and saving a list to view state but it needs to be serializable and i dont know how.

public List<ListItem> Items
{
    get
    {
        if (ViewState["ItemsList"] != null)
            return (List<ListItem>)ViewState["ItemsList"];
        else
            return Items;
    }
    set
    {
        ViewState["ItemsList"] = value;
    }
}

Upvotes: 0

Views: 1196

Answers (1)

Garrison Neely
Garrison Neely

Reputation: 3289

I believe the error is pointing to ListItem not being serializable. You won't be able to fix that, but you can create your own MyListItem class that is decorated with the [Serializable] attribute.

What I'd suggest as a better way is to investigate why you need to store a list of ListItems in ViewState instead of just binding it to the control that is storing that list.

Upvotes: 1

Related Questions