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

Forums / General Discussions / Simple view Control ID

Simple view Control ID

6 posts, 1 answered
  1. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    10 Nov 2010
    Link to this post
    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.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    10 Nov 2010
    Link to this post
    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
  3. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    11 Nov 2010
    Link to this post
    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.
      
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Nov 2010
    Link to this post
    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
  5. Paulo
    Paulo avatar
    19 posts
    Registered:
    03 Nov 2010
    11 Nov 2010
    Link to this post
    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.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Nov 2010
    Link to this post
    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
    Answered
6 posts, 1 answered