Get current content ID from field control?

Posted by Community Admin on 04-Aug-2018 07:04

Get current content ID from field control?

All Replies

Posted by Community Admin on 27-Feb-2013 00:00

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.???????
    

Posted by Community Admin on 23-Aug-2013 00:00

I am after this answer too Urgently...any solution?

Posted by Community Admin on 25-Aug-2013 00:00

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;

Posted by Community Admin on 16-Apr-2014 00:00

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.

 

Posted by Community Admin on 16-Apr-2014 00:00

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"]

This thread is closed