This is a migrated thread and some comments may be shown as answers.
How to load custom Web User Controls
1 Answer 8 Views
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 12 Nov 2014, 01:06 PM
Hi,

I have the following situation: I have multiple self-developed Web User Controls (ascx) in my web application. The user controls are holding different logic, for example a rather complex contact form.

Every page's content on the website, is edited throud RadEditor. Now I need a flexible way to dynamically load page content including one, two, three, x of my own custom user controls....

How can i accomplish this in a neat way with the RadEditor?

My own solution is, in the RadEditor's contentarea, to insert a reference to the user control like %%control:MyFancyUserControl%%, and then at runtime search for %%control:MyFancyUserControl%% and load the control when the page is rendered.

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 14 Nov 2014, 04:03 PM

Hello Thomas,

RadEditor for ASP.NET AJAX is an XHTML WYSIWIG editor and not a webforms/ASP editor like Visual Studio. With this in mind, you cannot load a user control in it in order to edit it and republish it. From what I can understand you need a content management system, so you can consider the Telerik SItefinity product.

What you can load in the editor is HTML, so you can have the user control  render to a dummy container if this fits your needs. Here is an example that you can use as base to render user controls to HTML in order to use that HTML:

Page pageHolder = new Page();
UserControl viewControl = (UserControl)pageHolder.LoadControl("~/WebUserControl.ascx");
pageHolder.Controls.Add(viewControl);
StringWriter output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
RadEditor1.Content = output.ToString();

With user control like this:

some literal text
<br />
<asp:Panel ID="Panel1" runat="server">
    <p>
        some paragraph in the asp Panel (div)
    </p>
</asp:Panel>
<asp:Label ID="Label1" Text="a label control" runat="server" />

you will get the following HTML in the editor:

some literal text
<br />
<div id="ctl00_Panel1">
<p>
some paragraph in the asp Panel (div)
</p>
</div>
<span id="ctl00_Label1">a label control</span>

Note that, in order to use form elements like textboxes or buttons, you should take some additional steps to have a form on the page used to render the user controls. Also, this is just one example, there are other ways to do this, and what is important is that neither approach offers a two-way conversion OOB, which means that when you edit the HTML in RadEditor, there is no built- in facility to translate it back into ASP markup.

Regards,

Marin Bratanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Asked by
Thomas
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or