serialization problem - eventhandling by control

R

Ralf Müller

Hi folks!

I am developing a custom TreeView and I have got a problem with the
serialization of my TreeViewModel:

[Serializable]
public class NavigationTreeModel : ITreeModel {

public event EventHandler DataChanged;

private Folder _rootFolder;
private IList _rootElements;

public NavigationTreeModel() : this(null) {
}

public NavigationTreeModel(Folder root) {
_rootElements = new ArrayList();
RootFolder = root;
}

public Folder RootFolder {
get { return _rootFolder; }
set {
if (_rootFolder == value)
return;
if (_rootFolder != null)
_rootElements.Remove(_rootFolder);
_rootFolder = value;
if (_rootFolder != null) {
_rootElements.Add(_rootFolder);
}
OnDataChanged(EventArgs.Empty);
}
}

#region ITreeModel Member

public IList RootElements {
get {
if (_rootElements == null) {
_rootElements = new ArrayList();
if(RootFolder != null)
_rootElements.Add(RootFolder);
}
return _rootElements;
}
}

public IList GetChildren(object parent) {
if (parent is Folder) {
return ((Folder)parent).Folders;
}
return new ArrayList();
}

#endregion

protected virtual void OnDataChanged(EventArgs e) {
if (DataChanged != null)
DataChanged(this, e);
}
}

The model serializes perfectly until I set my TreeViewControl to handle its
DataChangedEvent. Then I get the following exception:
"Der Typ 'julitec.DM.Web.NavigationTreeModel' muss als 'Serializable'
markiert sein oder einen anderen TypeConverter als ReferenceConverter
haben." (= The type 'julitec.DM.Web.NavigationTreeModel' must be marked as
Serializable or have a TypeConverter other than ReferenceConverter)
I guess that is because my TreeViewControl is not serializable.
What I am asking myself (and you) now is the following: Should I really make
a Control serializable? I don't think it is a good pratice to do so since
none of the built in ASP.NET WebControls seems to be serializable. What else
could I do to overcome this problem?

Thanx in advance!



Greetings, Ralf
 
R

Ralf Müller

hi leon!

my problem is that i want to notify my control of changes that occur to the
model - not the other way round
but i have got no idea how to send an event or any kind of notifcation to my
control if i can't let it handle my model events because it is not
serializable...

could you give me an example of what you where proposing?


ralf


Leon Friesema said:
Hi folks!

I am developing a custom TreeView and I have got a problem with the
serialization of my TreeViewModel:
[SNIP CODE]

The model serializes perfectly until I set my TreeViewControl to handle its
DataChangedEvent. Then I get the following exception:
"Der Typ 'julitec.DM.Web.NavigationTreeModel' muss als 'Serializable'
markiert sein oder einen anderen TypeConverter als ReferenceConverter
haben." (= The type 'julitec.DM.Web.NavigationTreeModel' must be marked as
Serializable or have a TypeConverter other than ReferenceConverter)
I guess that is because my TreeViewControl is not serializable.
What I am asking myself (and you) now is the following: Should I really make
a Control serializable? I don't think it is a good pratice to do so since
none of the built in ASP.NET WebControls seems to be serializable. What else
could I do to overcome this problem?

Thanx in advance!



Greetings, Ralf

That indeed is the problem, the control isn't serializable and no, you
don't want it to be.
What you want to do, if you want to serialize the data is handle the
control and data seperately. When a change has occured in the Control,
you post it back to your data and serialize that.
One minor problem though, when de-serializing you need to rewrite your
code because it needs to repopulate the control.

Leon.
 
R

Ralf Müller

First of all - Merry Xmas! :)

My Problem is that I've got one TreeModel and several TreeViews attached to
it. In the meanwhile I "solved" the problem storing my Model in the
Session-Collection so it does not have to be serialized on postback. But
still it would be interesting how to implement the MVC-Pattern correctly in
ASP.NET. But I guess I'd better put that in a new Post...

Greetings, Ralf


Leon Friesema said:
Leon Friesema said:
Hi folks!

I am developing a custom TreeView and I have got a problem with the
serialization of my TreeViewModel:

[SNIP CODE]

The model serializes perfectly until I set my TreeViewControl to
handle
its
DataChangedEvent. Then I get the following exception:
"Der Typ 'julitec.DM.Web.NavigationTreeModel' muss als 'Serializable'
markiert sein oder einen anderen TypeConverter als ReferenceConverter
haben." (= The type 'julitec.DM.Web.NavigationTreeModel' must be
marked
as
Serializable or have a TypeConverter other than ReferenceConverter)
I guess that is because my TreeViewControl is not serializable.
What I am asking myself (and you) now is the following: Should I
really
make
a Control serializable? I don't think it is a good pratice to do so since
none of the built in ASP.NET WebControls seems to be serializable.
What
else
could I do to overcome this problem?

Thanx in advance!



Greetings, Ralf


That indeed is the problem, the control isn't serializable and no, you
don't want it to be.
What you want to do, if you want to serialize the data is handle the
control and data seperately. When a change has occured in the Control,
you post it back to your data and serialize that.
One minor problem though, when de-serializing you need to rewrite your
code because it needs to repopulate the control.

Leon.

hi leon!

my problem is that i want to notify my control of changes that occur to the
model - not the other way round
but i have got no idea how to send an event or any kind of notifcation to my
control if i can't let it handle my model events because it is not
serializable...

could you give me an example of what you where proposing?


ralf

Ralf,

what do you mean by notify my control?
If you mean you added a Node to the TreeView == change to the Model.
In that case, why don't you override the methods of the node-changes
(add, remove, etc) and handle these events also within your
(serializable) model.

Leon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top