Problem storing Style in View State

Discussion in 'ASP .Net Building Controls' started by Rob, Jul 18, 2003.

  1. Rob

    Rob Guest

    I have created a custom control that has
    System.Web.UI.WebControls.Style has a property.

    The property is defined like this:

    [Bindable(true), Category("Style"),
    public virtual Style ValidationErrorStyle {
    get {
    if (ViewState["VALIDATION_ERROR_STYLE"] == null)
    ViewState["VALIDATION_ERROR_STYLE"] = new Style();
    return (Style)ViewState["VALIDATION_ERROR_STYLE"];

    Everything works great if I have a ValidationErrorStyle tag in the
    aspx page, like this:

    <SIERRACONTROL:LABELEDTEXTBOX id="SampleControl" runat="server">

    but if I remove the tag and have this:

    <SIERRACONTROL:LABELEDTEXTBOX id="SampleControl" runat="server">

    I get a "The type 'System.Web.UI.WebControls.Style' must be marked as
    Serializable or have a TypeConverter other than ReferenceConverter to
    be put in viewstate." Exception.

    I extended Style and created a SerializedStyle Class that I tried to
    use. I marked the class [Serializable], implemented ISerializable and
    the SerializableStyle, and GetObjectData methods. I still got the

    I am at a complete loss here. Funny thing is if I replace Style with
    TableItemStyle it works just fine. Also there are two other Style
    properies in the control and they just reference internal controls

    [Bindable(true), Category("Style"),
    public virtual Style TextBoxStyle {
    get { EnsureChildControls(); return txtBox.ControlStyle; }

    and they work fine too.
    Rob, Jul 18, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.