serialization problem - eventhandling by control

Discussion in 'ASP .Net Building Controls' started by Ralf Müller, Dec 14, 2004.

  1. Ralf Müller

    Ralf Müller Guest

    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
    Ralf Müller, Dec 14, 2004
    #1
    1. Advertising

  2. Ralf Müller

    Ralf Müller Guest

    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" <leon@@frostbits.nl> schrieb im Newsbeitrag
    news:...
    > On Tue, 14 Dec 2004 09:46:28 +0100, "Ralf Müller" <>
    > wrote:
    >
    > >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.
    Ralf Müller, Dec 16, 2004
    #2
    1. Advertising

  3. Ralf Müller

    Ralf Müller Guest

    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" <leon@@frostbits.nl> schrieb im Newsbeitrag
    news:...
    > On Thu, 16 Dec 2004 12:39:36 +0100, "Ralf Müller" <>
    > wrote:
    >
    > >
    > >
    > >"Leon Friesema" <leon@@frostbits.nl> schrieb im Newsbeitrag
    > >news:...
    > >> On Tue, 14 Dec 2004 09:46:28 +0100, "Ralf Müller" <>
    > >> wrote:
    > >>
    > >> >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.
    Ralf Müller, Dec 24, 2004
    #3
    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. Andrea
    Replies:
    0
    Views:
    360
    Andrea
    Dec 18, 2003
  2. Claes Rådström
    Replies:
    3
    Views:
    328
    Claes Rådström
    Feb 5, 2004
  3. Herfried K. Wagner [MVP]
    Replies:
    12
    Views:
    549
    =?Utf-8?B?YmFsbWVyY2g=?=
    Dec 1, 2005
  4. cm
    Replies:
    2
    Views:
    1,990
  5. Franz Fitz

    Problem with Eventhandling in user control

    Franz Fitz, Oct 30, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    116
    John Saunders
    Oct 30, 2003
Loading...

Share This Page