Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6072703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:11:22+00:00 2026-05-23T10:11:22+00:00

I created a really simple control that contains a list of filter option controls

  • 0

I created a really simple control that contains a list of filter option controls in much the same way that a listbox has a list of listitems.

I’m having some trouble tring to get it to serialize in to viewstate as the serializer appears to be trying to serialize the base class properties and basically i end up with errors like – cannot serialize property “page” What do you think is my problem?

The Code:

[Serializable]
public class FilterOption : Control, ISerializable
{
    public event EventHandler Checkchanged;

    CheckBox _chk = new CheckBox();
    Label _lbl = new Label();

    public string Text
    {
        get { return _lbl.Text; }
        set { _lbl.Text = value; }
    }

    public bool Checked
    {
        get { return _chk.Checked; }
        set { _chk.Checked = value; }
    }

    public FilterOption()
    {
        Controls.Add(new LiteralControl("<li>"));
        _chk.AutoPostBack = true;
        _chk.CssClass = "checkbox";
        Controls.Add(_chk);
        Controls.Add(_lbl);
        _chk.CheckedChanged += new EventHandler(_chk_CheckedChanged);
        Controls.Add(new LiteralControl("</li>"));
    }

    public FilterOption(string Text, bool Checked)
    {
        Controls.Add(new LiteralControl("<li>"));
        _chk.CssClass = "checkbox";
        _lbl.Text = Text;
        _chk.Checked = Checked;
        Controls.Add(_chk);
        Controls.Add(_lbl);
        _chk.CheckedChanged += new EventHandler(_chk_CheckedChanged);
        Controls.Add(new LiteralControl("</li>"));
    }

    public FilterOption(SerializationInfo info, StreamingContext context)
    {
        Controls.Add(new LiteralControl("<li>"));
        _chk.CssClass = "checkbox";
        _lbl.Text = (string)info.GetValue("Text", typeof(string));
        _chk.Checked = (bool)info.GetValue("Text", typeof(bool));
        Controls.Add(_chk);
        Controls.Add(_lbl);
        _chk.CheckedChanged += new EventHandler(_chk_CheckedChanged);
        Controls.Add(new LiteralControl("</li>"));
    }

    void _chk_CheckedChanged(object sender, EventArgs e)
    {
        if (Checkchanged != null)
            Checkchanged(this, new EventArgs());
    }


    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        if(info == null)
            throw new System.ArgumentNullException("info");

        info.AddValue("Text", _lbl.Text);
        info.AddValue("Checked", _chk.Checked);
    }
}

I literally only need to serialize the properties added to the serialization info in the GetObjectData method.

I’m using the following code to perform the serialization …

List<FilterOption> options = new List<FilterOption>();

    ... add some items to the collection ... 

StringWriter writer = new StringWriter();
XmlSerializer ser = new XmlSerializer(typeof(List<FilterOption>));
ser.Serialize(writer, options);
ViewState["Options"] = writer.ToString();

Oh yeh … i forgot to add … i got the information from here …
http://msdn.microsoft.com/en-us/library/ms973893.aspx

(in case it matters)

…

Thx Wardy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:11:22+00:00Added an answer on May 23, 2026 at 10:11 am

    Apparently you cannot serialize a type that inherits a non serializable type even ifyou do not wish to serialize the non-serializable properties of your derived type.

    I think this should be classed as a bug since the who point of interfaces like ISerializable is to specify exactly what it is you inted to serialize by manually implementing the method that handles the serialization.

    In any case the solution to my particular scenario was to not bother serializing at all and simply save the information of interest in to viewstate which would then be reused on postbacks to rebuild controls in the exact same state ready for the page based postback events to occur.

    Shame this isnt better documented somewhere because although microsoft does document the SaveViewState and LoadViewState methods of the page lifecycle they are very vague about how these events might be used, i’m guessing they are hoping someone in the community might provide an example.

    I would post my code but its a nasty hack to get everything working so i don’t thing it should be mainstream msdn code.

    Ok for a small internal app though 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Up till now I've used version control for simple web-based projects that don't really
This is really simple. I have a TableLayoutPanel that is populated with controls (just
I'm really new to Python and Django. I created a class in Python that
It seems that the RichTextBox control does not support copy&paste. Is it really so?
Maybe someone can help me out. I have created a simple web user control,
I've created a simple user control which is manually created with something like MyUserControl
My father has found a Russian language keyboard mapping that he really likes here
My issue is that I've created an extended RichTextBox control that uses native API
The issue is simple really. Instead of creating folders in Visual Studio, I create
i've created a dll for gamemaker. dll's arrays where really slow so after asking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.