Avoid properties persistence in ASP.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gilberto Carcano

    Avoid properties persistence in ASP.NET

    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
    ITrackingManage r 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 ?
  • Olorin

    #2
    Re: Avoid properties persistence in ASP.NET

    Puoi postare un esempio?

    Con serializzazione ad Xml, ad esempio, posso scrivere

    [XmlRoot(Element Name("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.

    Comment

    • Gilberto Carcano

      #3
      Re: Avoid properties persistence in ASP.NET

      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 IsTrackingViewS tate. 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 BrowsableAttrib ute(false)
      e
      DesignerSeriali zationVisibilit y(Hidden)
      come attributi della proprietà da "nascondere ".

      Non avevo googlato abbastanza :-<
      Grazie comunque.


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...