How to NOT serialize a Property of a Class

Discussion in 'ASP .Net' started by =?Utf-8?B?RWFybCBUZWlncm9i?=, Oct 4, 2004.

  1. I have a class that has some fields and properties that I want to serialize.
    However, one of the fields is of type System.Web.UI.Webcontrols.Webcontrol
    and it will not serialize so I want to mark it as "NonSerialized". However,
    this property is not allowed on a property of this type. How can I designate
    this property so that I can serialize the rest of the call without
    serializing this property???

    Thanks!

    Property myControl() As System.Web.UI.WebControls.WebControl
    Get
    Return _myControl
    End Get
    Set(ByVal Value As System.Web.UI.WebControls.WebControl)
    _myControl = Value
    End Set
    End Property
    =?Utf-8?B?RWFybCBUZWlncm9i?=, Oct 4, 2004
    #1
    1. Advertising

  2. Hi,

    The first thing that comes to mind is using two separate methods for
    getting/seting (eg: Get_myControl() and Set_myControl(Value As WebControl))
    the field (_myControl) instead of the property (myControl()). Then just mark
    the field _myControl with the NonSerializedAttribute.

    Hope this helps
    Martin
    "Earl Teigrob" <> wrote in message
    news:...
    > I have a class that has some fields and properties that I want to

    serialize.
    > However, one of the fields is of type System.Web.UI.Webcontrols.Webcontrol
    > and it will not serialize so I want to mark it as "NonSerialized".

    However,
    > this property is not allowed on a property of this type. How can I

    designate
    > this property so that I can serialize the rest of the call without
    > serializing this property???
    >
    > Thanks!
    >
    > Property myControl() As System.Web.UI.WebControls.WebControl
    > Get
    > Return _myControl
    > End Get
    > Set(ByVal Value As System.Web.UI.WebControls.WebControl)
    > _myControl = Value
    > End Set
    > End Property
    Martin Dechev, Oct 5, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?RWFybCBUZWlncm9i?=

    BluDog Guest

    <System.Xml.Serialization.XmlIgnore()> _
    Property myControl() As System.Web.UI.WebControls.WebControl
    Get
    Return _myControl
    End Get
    Set(ByVal Value As System.Web.UI.WebControls.WebControl)
    _myControl = Value
    End Set
    End Property


    Hope this helps

    Blu.
    BluDog, Oct 5, 2004
    #3
  4. Thank you Both ForYour answers. I used the combination of your answers to
    solve my issue and it works great! Here is what my class ends up looking like


    <Serializable()> _
    Class TabMenuItem
    ....
    <NonSerialized()> Private _RenderControl As
    System.Web.UI.WebControls.WebControl

    ....

    <System.Xml.Serialization.XmlIgnore()> _
    Property RenderControl() As System.Web.UI.WebControls.WebControl
    Get
    If Not _RenderControl Is Nothing Then
    Return _RenderControl
    Else
    _RenderControl =
    System.Activator.CreateInstance(ControlType)
    _RenderControl.ID = ControlId
    Return _RenderControl
    End If
    End Get
    Set(ByVal Value As System.Web.UI.WebControls.WebControl)
    _RenderControl = Value
    ControlType = Value.GetType
    ControlId = Value.ID
    End Set
    End Property
    ....

    End Class

    "Earl Teigrob" wrote:

    > I have a class that has some fields and properties that I want to serialize.
    > However, one of the fields is of type System.Web.UI.Webcontrols.Webcontrol
    > and it will not serialize so I want to mark it as "NonSerialized". However,
    > this property is not allowed on a property of this type. How can I designate
    > this property so that I can serialize the rest of the call without
    > serializing this property???
    >
    > Thanks!
    >
    > Property myControl() As System.Web.UI.WebControls.WebControl
    > Get
    > Return _myControl
    > End Get
    > Set(ByVal Value As System.Web.UI.WebControls.WebControl)
    > _myControl = Value
    > End Set
    > End Property
    =?Utf-8?B?RWFybCBUZWlncm9i?=, Oct 5, 2004
    #4
    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. Jonah Olsson

    Can I make a class from XML? Serialize?

    Jonah Olsson, Aug 8, 2003, in forum: ASP .Net
    Replies:
    12
    Views:
    496
  2. Craig Buchanan

    serialize class to the viewstate

    Craig Buchanan, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,156
  3. Gordz
    Replies:
    3
    Views:
    3,921
    John Oakes
    Jun 7, 2004
  4. cyberco
    Replies:
    5
    Views:
    3,124
  5. Stefaan V.

    How to serialize an extended property for a Webcontrol?

    Stefaan V., Oct 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    142
    Stefaan V.
    Oct 7, 2004
Loading...

Share This Page