Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Leiszen 4 posts 24 karma points
    Mar 17, 2010 @ 23:33
    Daniel Leiszen
    0

    Creating a custom datatype by implementing IData

    Hi,

    I was playing with the Umbraco API to figure out what would be the best scenario for me to implement my custom datatype. When to create the child controls, when to load the data and so on. In my test implementation I just wanted to explore the lifecycle of a datatype instance. I implemented four classes for the purpose, which were:

    CustomDataType: inherits form BaseDataType, implements IDataType

    CustomData: inherits from DefaultData

    CustomDataEditor: inherits from UserControl, implements IDataEditor

    CustomDataPrevalueEditor: inherits from UserControl, implements IDataPrevalue (this class does not play too much now)

    Every classes have a unique name, which is created automatically, and I traced all the method calls and object constructions which were initiated by the Umbraco runtime. These are the results for four different scenarios:

    1. creating the datatype by adding a new content
    2. loading the datatype by loading the content properties
    3. postback form the datatype ui by the one and only ui element which I used, a Button
    4. saving the datatype by saving the content properties
    Here are the results, which I cannot understand clearly:
    Create
    CustomDataType-1 CustomDataType.ctor
    CustomDataType-2 CustomDataType.ctor
    CustomDataType-2 CustomDataType.Data get
    CustomData-1 CustomData.ctor
    CustomData-1 CustomData.MakeNew
    CustomDataType-3 CustomDataType.ctor
    CustomDataType-3 CustomDataType.Data get
    CustomData-2 CustomData.ctor
    CustomData-2 CustomData.LoadValueFromDatabase
    CustomDataType-4 CustomDataType.ctor
    CustomDataType-4 CustomDataType.Data get
    CustomData-3 CustomData.ctor
    CustomData-3 CustomData.LoadValueFromDatabase
    CustomDataType-5 CustomDataType.ctor
    CustomDataType-5 CustomDataType.DataEditor get
    CustomDataEditor-1 CustomDataEditor.ctor
    CustomDataType-5 CustomDataType.Data get
    CustomData-4 CustomData.ctor
    CustomData-4 CustomData.LoadValueFromDatabase
    CustomDataType-5 CustomDataType.DataEditor get
    CustomDataType-5 CustomDataType.DataEditor get
    CustomDataType-5 CustomDataType.DataEditor get
    CustomDataType-5 CustomDataType.DataEditor get
    CustomDataType-6 CustomDataType.ctor
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataEditor-2 CustomDataEditor.ctor
    CustomDataType-5 CustomDataType.DataEditor get
    CustomDataEditor-1 CustomDataEditor.OnLoad
    CustomDataEditor-1 CustomDataEditor.CreateChildControls
    Load
    CustomDataType-1 CustomDataType.ctor
    CustomDataType-2 CustomDataType.ctor
    CustomDataType-2 CustomDataType.Data get
    CustomData-1 CustomData.ctor
    CustomData-1 CustomData.LoadValueFromDatabase
    CustomDataType-3 CustomDataType.ctor
    CustomDataType-3 CustomDataType.DataEditor get
    CustomDataEditor-1 CustomDataEditor.ctor
    CustomDataType-3 CustomDataType.Data get
    CustomData-2 CustomData.ctor
    CustomData-2 CustomData.LoadValueFromDatabase
    CustomDataType-3 CustomDataType.DataEditor get
    CustomDataType-3 CustomDataType.DataEditor get
    CustomDataType-3 CustomDataType.DataEditor get
    CustomDataType-3 CustomDataType.DataEditor get
    CustomDataType-4 CustomDataType.ctor
    CustomDataType-4 CustomDataType.DataEditor get
    CustomDataEditor-2 CustomDataEditor.ctor
    CustomDataType-3 CustomDataType.DataEditor get
    CustomDataEditor-1 CustomDataEditor.OnLoad
    CustomDataEditor-1 CustomDataEditor.CreateChildControls
    Postback
    CustomDataType-5 CustomDataType.ctor
    CustomDataType-5 CustomDataType.Data get
    CustomData-3 CustomData.ctor
    CustomData-3 CustomData.LoadValueFromDatabase
    CustomDataType-6 CustomDataType.ctor
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataEditor-3 CustomDataEditor.ctor
    CustomDataType-6 CustomDataType.Data get
    CustomData-4 CustomData.ctor
    CustomData-4 CustomData.LoadValueFromDatabase
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataType-7 CustomDataType.ctor
    CustomDataType-7 CustomDataType.DataEditor get
    CustomDataEditor-4 CustomDataEditor.ctor
    CustomDataType-6 CustomDataType.DataEditor get
    CustomDataEditor-3 CustomDataEditor.OnLoad
    CustomDataEditor-3 CustomDataEditor.CreateChildControls
    CustomDataEditor-3 CustomDataEditor.Button_Click
    Save
    CustomDataType-12 CustomDataType.ctor
    CustomDataType-12 CustomDataType.Data get
    CustomData-8 CustomData.ctor
    CustomData-8 CustomData.LoadValueFromDatabase
    CustomDataType-13 CustomDataType.ctor
    CustomDataType-13 CustomDataType.DataEditor get
    CustomDataEditor-7 CustomDataEditor.ctor
    CustomDataType-13 CustomDataType.Data get
    CustomData-9 CustomData.ctor
    CustomData-9 CustomData.LoadValueFromDatabase
    CustomDataType-13 CustomDataType.DataEditor get
    CustomDataType-13 CustomDataType.DataEditor get
    CustomDataType-13 CustomDataType.DataEditor get
    CustomDataType-13 CustomDataType.DataEditor get
    CustomDataType-14 CustomDataType.ctor
    CustomDataType-14 CustomDataType.DataEditor get
    CustomDataEditor-8 CustomDataEditor.ctor
    CustomDataType-13 CustomDataType.DataEditor get
    CustomDataEditor-7 CustomDataEditor.OnLoad
    CustomDataEditor-7 CustomDataEditor.
    CustomDataType-15 CustomDataType.ctor
    CustomDataType-15 CustomDataType.Data get
    CustomData-10 CustomData.ctor
    CustomData-10 CustomData.LoadValueFromDatabase
    CustomData-10 CustomData.Value get
    CustomDataEditor-7 CustomDataEditor.CreateChildControls
    The numbers after the type name are instance indexes. According to the results, for a simple postback, LoadValueFromDatabase method is called two times. During save, it is called three times. At least two instances are created from every object for every scenario.
    I know that ASP.Net is a kind of complicated technology, with weird behavior. Now what I don't know, how I can distinguish the calls from each other, to avoid loading my data multiple times? (Don't say I should count the calls.) I am a bit confused now.
    I am sure, there is a rational explanation. Any comment is appreciated. I can upload or send the full commented source code, if needed.
    Thanks

  • Paul Sterling 718 posts 1534 karma points MVP 9x admin c-trib
    Jun 10, 2010 @ 13:43
    Paul Sterling
    0

    Daniel -

    Just came across your post...have a look at the post Tim put together covering this topic for some ideas

    http://www.nibble.be/?p=50

    -Paul

Please Sign in or register to post replies

Write your reply to:

Draft