Problem storing Style in View State

R

Rob

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.
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top