473,405 Members | 2,154 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,405 software developers and data experts.

Storing and Exposing a Complex Object Property In Viewstate

I have a custom server control that exposes a property which is a
complex type. I expose the property as such:

public class Automobile
{
public AutomobileEngine Engine
{
get
{
object o = ViewState["Engine"];
if (o == null)
return new AutomobileEngine();
else
return (AutomobileEngine)o;
}
private set
{
ViewState["Engine"] = value;
}
}
}

It seems that there is a problem persisting values of Engine in
ViewState when it's exposed in this manner. If I code something like
this...

MyAutomobile.Engine.Cylinders = 6;

....the value isn't persisted unless I re-assign the property....

AutomobileEngine eng = MyAutomobile.Engine;
eng.Cylinders = 123;
MyAutomobile.Engine. = eng;

Is there a better way of exposing the property so changing properties
of the complex object remain in ViewState without having to re-assign
it back into the ViewState?
Aug 8 '08 #1
1 2317
you have a coding bug. if the object is not in view, you always return a new
object, you never store the new object in viewstate.
-- bruce (sqlwork.com)
"daokfella" wrote:
I have a custom server control that exposes a property which is a
complex type. I expose the property as such:

public class Automobile
{
public AutomobileEngine Engine
{
get
{
object o = ViewState["Engine"];
if (o == null)
return new AutomobileEngine();
else
return (AutomobileEngine)o;
}
private set
{
ViewState["Engine"] = value;
}
}
}

It seems that there is a problem persisting values of Engine in
ViewState when it's exposed in this manner. If I code something like
this...

MyAutomobile.Engine.Cylinders = 6;

....the value isn't persisted unless I re-assign the property....

AutomobileEngine eng = MyAutomobile.Engine;
eng.Cylinders = 123;
MyAutomobile.Engine. = eng;

Is there a better way of exposing the property so changing properties
of the complex object remain in ViewState without having to re-assign
it back into the ViewState?
Aug 8 '08 #2

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

Similar topics

4
by: Peter Hemmingsen | last post by:
Hi, I have a dotnet object (implemented in mc++ and used in c#) which have a property called "Info". The Info property is also a dotnet object (implemented in mc++). In the constructor of the...
1
by: igitur | last post by:
Hi all, I have a custom collection derived from System.Collections.Specialized.NameObjectCollectionBase. NameObjectCollectionBase already implements ISerializable, so it should be easy to...
1
by: 234 | last post by:
I'm playing around with page inheritence and I'm to the point now where I want to create a form object on a derived page. Here's a truncated version of my 'base' page from which all/most pages in...
2
by: ce | last post by:
Being a newbie regarding serialization and memorystreams, I was trying to see if i could improve page performance (avoiding going to the db on a postback) by saving my serialized business object in...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
by: David Whitchurch-Bennett | last post by:
Hi There, I have created a very simple web user control, containing only a combo box. I have created a class which contains some private object variables, for example... Private _anObject as...
3
by: Adrian Parker | last post by:
v1.1 and v2.0 We have a problem with viewstate not being stored. What's happening is that we create controls in CreateChildControls and add them to a container on the page (whether it be a...
3
by: Mark | last post by:
I'm consuming a webservice that makes a simple object available. The object class is marked in the web service as . I have a web application that consumes and uses this web service's class. When...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.