Simple view Control ID
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)
...
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;
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.
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
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.
Hello Paulo,
You can use the container ID to identify the control -
ContainerId |
Gets the ID of the container of this control.
|