Copied to clipboard

Flag this post as spam?

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


  • Ulrik Knudsen 14 posts 25 karma points
    Oct 09, 2009 @ 14:53
    Ulrik Knudsen
    0

    Mediapicker / contentpicker in edit page in custom section.

    Hi,

    I use Umbraco v. 4.0.2.1.

    I have made a custom section, that loads data from a custom table. Rendering of the tree and editing of data works fine.

    Now I want to relate the entities in the custom table to 'standard' umbraco content/media.

    How can I insert a contentpicker or a mediapicker in my custom 'edit custom entity' web form (so I can save the selected node id in the custom table)?

    Best regards

    Ulrik

     

  • Comment author was deleted

    Oct 09, 2009 @ 14:57

    First you'll need a class that inherits from IData,

     public class DataExtractor : IData
    {
    private object _value;

    public DataExtractor() { }
    public DataExtractor(object o)
    {
    Value = o;
    }

    #region IData Members

    public void Delete()
    {
    throw new NotImplementedException();
    }

    public void MakeNew(int PropertyId)
    {
    throw new NotImplementedException();
    }

    public int PropertyId
    {
    set { throw new NotImplementedException(); }
    }

    public System.Xml.XmlNode ToXMl(System.Xml.XmlDocument d)
    {
    throw new NotImplementedException();
    }

    public object Value
    {
    get
    {
    return _value;
    }
    set
    {
    _value = value;
    }
    }

    #endregion
    }

     

    Then add these:

    private umbraco.editorControls.pagePicker contentPicker;
    private DataExtractor dataExtractor;

    Now you can add the contentpicker to a control collection, oninit (in this case a placeholder with id phContentPicker)

    dataExtractor = new DataExtractor();
    contentPicker = new umbraco.editorControls.pagePicker(dataExtractor);
    phContentPicker.Controls.Add(contentPicker);

     

     

  • Ulrik Knudsen 14 posts 25 karma points
    Oct 09, 2009 @ 15:49
    Ulrik Knudsen
    0

    Wonderful :-)

    And with the mediapicker I suppose it would be something like:

    _dataExtractor = new DataExtractor();
    _mediapicker = new mediaChooser(_dataExtractor);
    MediaPickerPlaceHolder.Controls.Add(_mediapicker);

    But how do I get the selected node id?

    Best regards
    Ulrik

  • Masood Afzal 176 posts 522 karma points
    Oct 11, 2009 @ 15:40
    Masood Afzal
    0
    dataExtractor.Value 

    or

    dataExtractor.Value.ToString()
  • Peter Cort Larsen 421 posts 1038 karma points
    Feb 23, 2010 @ 14:59
    Peter Cort Larsen
    0

    Hi,

    I have succesfully added the above code to the edit page of my custom tree.

    But can anyone tell me, how a field that contains media data, should be formatted in a the custom table?

     

  • Daniel Bardi 927 posts 2562 karma points
    Jun 16, 2010 @ 03:39
    Daniel Bardi
    0

    Why didn't you simply use the ContentPicker control (umbracon.controls.ContentPicker).. this would give you the media tree in a dialog.

  • mfeola 117 posts 221 karma points
    Oct 29, 2010 @ 18:53
    mfeola
    0

    Initialization of the picker works fine for me.  I create the picker and i create the extractor and set the value of the extractor and on the admin side it gets populated correctly.  Right now though, i cant seem to get the value after i change the value in the picker?  i keep getting null reference exceptions whenever i use dataextractor.value after changing the value of the picker

    anyone experience this?

  • Jacob 39 posts 88 karma points
    Nov 25, 2010 @ 09:53
    Jacob
    0

    I have tried this aswell..

    But I wanted to use the ContentPicker, but my problem was when I did the following:

     DataTypeDefinition dataTypeDefinition1 = DataTypeDefinition.GetDataTypeDefinition(1034);
     umbraco.controls.ContentPicker mediaPicker = (umbraco.controls.ContentPicker)dataTypeDefinition1.DataType.DataEditor;
    
     mediaPicker.AppAlias = "media";
     mediaPicker.TreeAlias = "media";
    
     PlaceholderMediaPicker.Controls.Add(mediaPicker);

    I got a cast error, saying that my datatype was pagePicker, eventhough the database said the ID 1034 is the ContentPicker, anyone who can help with that?

    After that I tried the example above, and got the mediapicker, but I cannot seem to get the value after I change the selection.

    In either case I would like to be able to run a Javascript function after the select has been done, any input about how that could be done?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 25, 2010 @ 10:17
    Jeroen Breuer
    0

    Hi Jacob,

    Here you can find a good example how you can add the media picker to a custom section: http://our.umbraco.org/forum/developers/extending-umbraco/13518-implement-improved-mediapicker-c. It also places the datatype on a custom page.

    Jeroen

  • Jacob 39 posts 88 karma points
    Nov 25, 2010 @ 10:25
    Jacob
    0

    Hey, allready tried those examples, and it is not an option for me to alter the souce code of Umbraco.

    I got to the point where I have the mediapicker with:

    private umbraco.editorControls.mediaChooser _mediapicker;
    DataTypeDefinition dataTypeDefinition1 = DataTypeDefinition.GetDataTypeDefinition(1035);
    umbraco.editorControls.mediaChooser _mediapicker = (umbraco.editorControls.mediaChooser)dataTypeDefinition1.DataType.DataEditor;
    
    PlaceholderMediaPicker.Controls.Add(_mediapicker);            
    

    Where the definition is in the top of the class, and the rest in the onInit override.

    I can assign a value to it, and it has that when being drawn, but if I change the value, or just pushes a button which does a postback, then when I try to get the value in the onclick method I get "Object reference not set to an instance of an object."

    Have I forgotten somthing obvious?

  • Greg 14 posts 34 karma points
    Jan 17, 2011 @ 15:49
    Greg
    0

    RE: Tim Gayssens' post. When the page is submitted, how do you get the value from the DataExtractor? On Postback the DataExtractor is being re-created and it's value is Null.

  • Matt Bliss 176 posts 234 karma points c-trib
    Aug 01, 2012 @ 17:39
    Matt Bliss
    0

    I've just worked out this simple solution based on a combination of the various comments in this post. (I'm using 4.7.2)

    I've got a placeholder (phMedia) in my user control where I want the media picker.

    In my 'Page_Load' function I define the following:

        umbraco.controls.ContentPicker contentPicker;
    contentPicker = new umbraco.controls.ContentPicker();
        contentPicker.AppAlias = "media";
        contentPicker.TreeAlias = "media";
        phMedia.Controls.Add(contentPicker);

    To set the media picker to display the stored value:

        contentPicker.Value = myStoredValue;

    To save the selected value in my 'save_Click' function:

        foreach (Control control in phMedia.Controls)
        {
            if (control.GetType() == typeof(umbraco.controls.ContentPicker))
            {
                umbraco.controls.ContentPicker contentPicker = (umbraco.controls.ContentPicker)control;
                myValueToSave = contentPicker.Value;
            }
        }

    I hope this helps someone else!

  • pat 124 posts 346 karma points
    Jul 25, 2013 @ 15:55
    pat
    0

    I am getting null object reference error when I am trying to set value, I have tried just read  contentpicker and the above method , but I don't get the value

    please help

Please Sign in or register to post replies

Write your reply to:

Draft