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"),
    PersistenceMode(PersistenceMode.InnerProperty),
    NotifyParentProperty(true),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    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">
    <VALIDATIONERRORSTYLE cssclass="testing"></VALIDATIONERRORSTYLE>
    </SIERRACONTROL:LABELEDTEXTBOX>

    but if I remove the tag and have this:

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

    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
    error.

    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
    via:

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

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

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. toton
    Replies:
    11
    Views:
    712
    toton
    Oct 13, 2006
  2. Replies:
    1
    Views:
    565
    Victor Bazarov
    Feb 1, 2007
  3. Jonathan Wood
    Replies:
    1
    Views:
    511
    Jonathan Wood
    Jun 2, 2008
  4. Ken Varn
    Replies:
    0
    Views:
    472
    Ken Varn
    Apr 26, 2004
  5. Parthiv Joshi
    Replies:
    1
    Views:
    706
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page