473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to NOT serialize a Property of a Class

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
Nov 18 '05 #1
3 2724
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" <Ea*********@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
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

Nov 18 '05 #2
<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.
Nov 18 '05 #3
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

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Manion via .NET 247 | last post by:
Long Post, thanks for your patience... I have and XML file that looks something like this: <?xml version="1.0" encoding="utf-8" ?> <Settings> <Location> <X>30</X> <Y>40</Y> </Location>...
1
by: Rick Luckwell | last post by:
I have 3 collections(reports, services, charts) of objects(report, service, chart) that are nested with each other. When I serialize the object the output only contains reports and services but...
1
by: davebaranas | last post by:
I am able to serialize this but I get a null exception when I try to deserialize it back Even if I don't make any child classes it throws "Object reference not set to an instance of an object."...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.