Simple view Control ID

Posted by Community Admin on 03-Aug-2018 15:39

Simple view Control ID

All Replies

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

Hi,

I, would like to know how can we get the PageControl ID  (the GUID saved in the database) in our rendered custom User Control  in preview or design mode.

public class WebTemplateViewer : SimpleView
    ...
    protected override void InitializeControls(GenericContainer container)
    
        ...
        controlId = this.ID; // this.ID shoud return the GUID of the pageControl saved in database and NOT the "C0001"
 
        // load templates available for this module, configured elsewere
        LoadControlTemplates(controlId) 
            ...
    

Is this possible?


Thanks in advance.

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

Hi Paulo,

Here is a sample code that shows how to get the control id

var pageManager = PageManager.GetManager();
var page = pageManager.GetPageNodes().Where(p => p.Page.Title == "page1").SingleOrDefault();
if (page.Page.Controls.Count > 0)
    foreach (ControlData ctrl in page.Page.Controls)
    
        if (ctrl.Caption == "Class4")
        
            var id = ctrl.Id;
        
    


Regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

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

Hi.

Thanks for the help, but this way I must know the title of the page where the current control instance is inserted, and unfortunatly  the  "this.Page"  have the attribute (this.Page.Title == "").

And there is also a problem to obtain the ctrl.caption, let's supose that there are 2 or many controls of the same type in the same page... we cannot know wich one is our current control unless we parse throug the properties and find the instance (ex ID="C001").

It would be Helpfull, if there is an easier way to do it.


Thanks for your support.
  

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

Hello Paulo,

You should know some parameter of the query. You can loop though all pages but this will cause some performance issues if you have a large SiteMap. You can try to use one of the other properties of ControlData  as an identifier.

Sincerely yours,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

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

Hi

I can't figure out what you mean by "You can try to use one of the other properties of ControlData  as an identifier.".
Can you send me a sample code to acomplish that?

Thanks in advance.

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

Hello Paulo,

You can use the container ID to identify the control -

ContainerId
Gets the ID of the container of this control.

If you have one type an many instances of it you should use some value of a public property as an identifier.
The case is the same if you put two or more ASP.NET Label controls on the same page and you should identify them.

Regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed