Add Custom UserControls Registered in the Toolbox using Code
Hi jaime,
Below is a sample code that illustrates how to add custom control to a page and set its property.
public
partial
class
SampleControl : System.Web.UI.UserControl
protected
override
void
OnLoad(EventArgs e)
base
.OnLoad(e);
this
.Trigger.Click +=
new
EventHandler(Trigger_Click);
this
.Literla1.Text = ShowText;
void
Trigger_Click(
object
sender, EventArgs e)
var mgr = PageManager.GetManager();
var pg = mgr.GetPageNodes().Where(t => t.Title ==
"FirstPage"
).FirstOrDefault();
var pageCtrl = mgr.CreateControl<PageControl>(
"~/Controls/SampleControl.ascx"
,
"E2268733001_Col00"
);
ControlProperty prop = pageCtrl.Properties.Where(p => p.Name ==
"ShowText"
).FirstOrDefault();
if
(prop ==
null
)
prop = mgr.CreateProperty();
prop.Name =
"ShowText"
;
pageCtrl.Properties.Add(prop);
prop.Value =
"SomeText"
;
pg.Page.Controls.Add(pageCtrl);
mgr.SaveChanges();
public
string
ShowText
get
;
set
;
It seems I am missing some references. Is this example good for 3.7?
I see I posted in the wrong forum. Can you transfer this to the other forum or do I need to make another post?
Hi jaime,
This does not work in 3.x editions. This is code for Sitefintiy 4.0, since the code you forum thread you use is for Sitefinity 4.0.
Best wishes,
Ivan Dimitrov
the Telerik team
We are using Sitefinity 4.0 beta version.
I have added my user controls to the tool box using sitefinity admin tool as described in the below link
http://www.sitefinity.com/40/help/developer-manual/controls-adding-a-new-control.html
I have observed that it is updating the file 'ToolboxesConfig.config' .Is there any db changes, it is performing other than these changes?
But When I try to add the User control to a page,I am not able to see it in the Tool box on the right side of the Page Edit section.
How can I add it to a page using admin tool by drag drop as we did in sitefinity previous versions.
Thanks
Venkat
Hi Venkat,
Try registering the control through the UI - Toolboxes section and then restart the application. The control should appear in the widget toolbox after restart.
All the best,
Ivan Dimitrov
the Telerik team
I have added Image gallery control to a page and published it.
When I re open the page for editing,I can not edit the control or delete it.
this is happening to all content control.Is it a bug in sitefinity 4.0 beta vesrion?.
Download list control not displaying the thumb nails ,How can we display thumb nails.
we have added the control to the page and set the thumb image too. but it is not showing on the list.Is it a bug or do we need to do some work around to get this?.
Ivan,
Thank you for you reply.
Now it is working fine.I think its responding slowly.
I am able to edit the controls and delete them.
I successfully added my user control onto the page now.
Hi Venkat,
It should not respond slowly if there are just a several documents or images.
Regards,
Ivan Dimitrov
the Telerik team
Hello Ivan,
Hi Robert,
I attached short video in another thread where I am showing how to register a custom control. The process of registering user controls is the same, but you should enter virtual path for user controls instead of the class library type.
Regards,
Ivan Dimitrov
the Telerik team
Hi Ivan,
Hello Robert,
There should not be a problem to create a new section, but there is an issue when you try to create a page if you do not have a tool in this section.
Sincerely yours,
Ivan Dimitrov
the Telerik team