+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get current content ID from field control?

Get current content ID from field control?

5 posts, 0 answered
  1. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    27 Feb 2013
    Link to this post

    In a field control, is there a way to get the parent content ID of the field control? For example, how would I get the content object or ID from inside InitializeControls of a field control?

    public class MyCustomFieldControl : FieldControl
    {
        protected override void InitializeControls(GenericContainer container)
        {
           var contentItem = this.???????
        }
    }

  2. Bishoy
    Bishoy avatar
    27 posts
    Registered:
    15 Aug 2013
    23 Aug 2013
    Link to this post
    I am after this answer too Urgently...any solution?
  3. Bishoy
    Bishoy avatar
    27 posts
    Registered:
    15 Aug 2013
    25 Aug 2013 in reply to Bishoy
    Link to this post
    Weird but true, The best I have reached is to read the parent dynamic content from the query string 
    #region Methods
    protected override void InitializeControls(GenericContainer container)
    {
     
    //I already know the type of the parent although you can find it too in the querystring
    Type parentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.MobileHomeData.Productfinder");
     
    //Reading parent GUID from the querystring , Then getting this parent record
    var master = dynamicModuleManager.GetDataItem(parentType, new Guid(Page.Request.QueryString["parentId"]));
     
    //Now simply read the value you are looking for form the parent record
    var prodTypeTitle = master.GetValue<Lstring>("ProductType").Value;
  4. Ben
    Ben avatar
    44 posts
    Registered:
    27 Sep 2012
    16 Apr 2014
    Link to this post

    You guys get anywhere on this? I have a custom field on the Events module that uses a custom field control and I'd like to get the id of the event I'm currently editing when the control loads.

     

  5. Ben
    Ben avatar
    44 posts
    Registered:
    27 Sep 2012
    16 Apr 2014
    Link to this post

    Alright, I figured this one out. Since I was working with events, I went to Admin -> Settings -> Events -> Controls -> EventsBackend -> Dialogs -> ContentViewEditDialog, then in the Parameters attribute you can see all the params that get returned when you request the query string. So just add &id={{Id}} and then in your field control:

    var stringId = HttpContext.Current.Request.QueryString["id"]

5 posts, 0 answered