Obtain control ID at ControlDesignerBase

Posted by Community Admin on 05-Aug-2018 20:39

Obtain control ID at ControlDesignerBase

All Replies

Posted by Community Admin on 28-Nov-2010 00:00

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

Posted by Community Admin on 28-Nov-2010 00:00

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.

Posted by Community Admin on 28-Nov-2010 00:00

Thanks for the quick answer.

--
Paulo

Posted by Community Admin on 30-Nov-2010 00:00

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

Posted by Community Admin on 01-Dec-2010 00:00

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.

Posted by Community Admin on 02-Dec-2010 00:00

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.

Posted by Community Admin on 02-Dec-2010 00:00

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.

This thread is closed