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

Forums / Sitefinity SDK / Obtain control ID at ControlDesignerBase

Obtain control ID at ControlDesignerBase

7 posts, 0 answered
  1. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    28 Nov 2010
    Link to this post
    Hi

    I need to populate a dropdownList in the custom control designer and I Would like to kwnow how can i find the controlID  (ex: "..ct002_C001") of the control instance that calls the controlDesigner

    And Why is Page.Title = null? The controlDesigner doesn't know the page where it is instaciated?
     

    public class WTFrontendDesigner : ControlDesignerBase
        {
            ...
          protected override void InitializeControls(GenericContainer container)
          {
              WTManager wtm = new WTManager();
                  
              string id = Page.Title  + //controlID of the instance control like  ..._ct001_C001
      
              TemplatesList.DataSource = wtm.GetModuleTemplates(id);
              this.DesignerMode = ControlDesignerModes.Simple;
          }
      
          protected virtual DropDownList TemplatesList
          {
              get
              {
                  return base.Container.GetControl<DropDownList>("TemplatesList", true);
              }
          }
    ...
    }

    Thanks in advance.

    --
    Paulo Dinis
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Nov 2010
    Link to this post
    Hello Paulo,

    Inside ControlDesignerBase class there is a public property of type Guid - ControlId . This property gets or sets the control id of the control for which the properties are being edited. By this property you can find the control on a page and ID property.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    28 Nov 2010
    Link to this post
    Thanks for the quick answer.

    --
    Paulo
  4. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    30 Nov 2010
    Link to this post
    Hi

    althoug i 've tryed diferent ways  to find the page I couldn't achieve the goal...
    Don't know how to do it properly,
    here is a way i've tryed

    using (var sf = App.WorkWith())
               {
                   sf.Pages().ForEach(pag =>
                   {
                       if (pag.Page != null)
                       {
                           var pc = pag.Page.Controls.ToList<PageControl>().Where(pct => pct.Id == ControlId).FirstOrDefault();
                           if (pc != null)
                           {
                               this.PageTitle = pc.Page.Title;
                               this.PageID = pc.Page.Id;
                               //this.CtrlID = pc.
                           }
                       }
                   });
               }

    Can you help me, posting a sample code ?

    Thanks
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Dec 2010
    Link to this post
    Hi Paulo,

    I am no sure why you are trying to do. When you have a custom ControlDesigner you can forces the designer to apply the changes on UI to the control data - some property by using applyChanges function. Please take a look at this tutorial.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    02 Dec 2010
    Link to this post
    Hi

    What i am trying to do is to load a list of predifened texts that my Widget can use,
    that list is defined elsewere in another module  page,

    I use the "Page title"  and "controlID" to identify a widget instance on a page

    here is a image to explain better.


    thanks.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Dec 2010
    Link to this post
    Hello Paulo,

    If you have only one control of the same type on a page you can get the PageID from the Context and then look at the page controls collection and get the control of your type.
    There will be a problem if you have two or more controls on the same page. Then you need to parameters to identify then - page ID, PlaceHolder  or a custom property in the designer where you explicitly set some value.

    The better option here is using two different controls which will allow you to identify them easily. Generally you can create one base control and create some other controls that inherit from it.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
7 posts, 0 answered