Avoid properties persistence in ASP.NET

  • Thread starter Thread starter Gilberto Carcano
  • Start date Start date
G

Gilberto Carcano

Is there a way to avoid public custom properties to persist in the
ASPX code?
I'have a class for columns collection in a Web Control i'm writing.
This class must to implement the IStateManager interface and so the
ITrackingManager read-only property is required. When the control
persist the collection it persist this property too and generate a
runtime error.
I've readed abouth the NotSerialized attribute but it's a solution for
public fiels only (not for properties).
Is there anyone can help me ?
 
Puoi postare un esempio?

Con serializzazione ad Xml, ad esempio, posso scrivere

[XmlRoot(ElementName("MyClass"))]
public class MyClass
{
private string s = "Ciao";

[XmlIgnore]
public string MyProperty
{
get { return s; }
set { s = value; }
}
}

hmmmm.... mi sa che non ho capito il tuo problema, o che la
serializzazione che stai facendo tu segue regole diverse da quella per
Xml che ho usato io.

F.O.R.
 
Scusa se non ho descritto bene il mio problema:
Stò scrivendo un Web Control che richiede una proprietà di tipo derivato
da CollectionBase. Per poter gestire correttamente il ViewState questo
tipo deve implementare l'interfaccia IStateManager che richiede una
proprietà pubblica IsTrackingViewState. Se definisco questa proprietà e
non uso nessun attributo ottengo due effetti indesiderati:
1) la proprietà viene listata nel properties browser a design time
2) la proprietà viene resa persistente nel codice ASPX della pagina che
contiene il controllo.

Ho comunque risolto entrambi i problemi usando BrowsableAttribute(false)
e
DesignerSerializationVisibility(Hidden)
come attributi della proprietà da "nascondere".

Non avevo googlato abbastanza :-<
Grazie comunque.
 
Back
Top