This is a migrated thread and some comments may be shown as answers.

[Solved] Creating RadEditor from a Class

3 Answers 157 Views
Editor
This is a migrated thread and some comments may be shown as answers.
John Guinto
Top achievements
Rank 1
John Guinto asked on 24 Dec 2009, 11:56 AM
Hi all, good day. I am wondering if its possible to create a radeditor in a class (not in a codebehind) and call the function that holds it in aspx. It will be helpful if I can cut my way through setting up all the editors in different pages when most of them have the same settings. I know I can use user control but I am trying to avoid creating multiple ascx files for different reasons. Consider the following code that works (Unfortunately, this is inside a codebehind not a class ): 

namespace UserControlTest 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            createGenericEditor(); 
        } 
 
        private void createGenericEditor() 
        { 
            RadEditor loadEditor = new RadEditor(); 
            loadEditor.ID = "RadEditor1"
            this.Controls.Add(loadEditor); 
        } 
    } 

how do i do this in a class then call it in ASPX say <%# Class1.createGenericEditor() %>

thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 25 Dec 2009, 09:04 AM
Hi John,

Please, find attached the requested example.


Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
John Guinto
Top achievements
Rank 1
answered on 26 Dec 2009, 08:52 PM
Hi Rumen. Thank your for responding to my question. I checked the sample you gave but unfortunately, the solution i am looking for is how to programatically create radeditor from a Class aside from a codebehind. I got it solved but, it presents a newer problem that perhaps you might be able to tell me what to do. Here is my solution.

A class different from codebehind
namespace UserControlTest  
    public partial class Class1 : System.Web.UI.Page 
    { 
        public static void showRadEditor(Page thisPage) 
        { 
            RadEditor myEditor = new RadEditor(); 
            myEditor.ID = "RadEditor1"
            thisPage.Controls.Add(myEditor); 
             
        } 
    } 

Codebehind
using UserControlTest; 
 
 
namespace UserControlTest 
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            Class1.showRadEditor(this); 
        } 
 
 
 
    } 
 

This works if I will call it inside a pageload of a codebehind, but my problem now is, I want to call the function in ASPX. It has something to do with layout so it will be more convenient to me to call it inside ASPX and when i call it like this:

<%# UserControlTest.Class1.showRadEditor(this) %>

I am getting an error saying "Cannot implicitly convert type void to object"

I am not sure if this is possible because i am new to dotnet. I am thinking that if I can have a collection of  functions in a class, they can just be called easily.

happy holidays. :-)
regards,
John




0
John Guinto
Top achievements
Rank 1
answered on 26 Dec 2009, 09:15 PM
Hi Rumen,

By using the sample you gave, I think I got it working by using Placeholder controls.

Instead of declaring it as a page
public static void showRadEditor(Page thisPage)

I changed it to control
public static void showRadEditor(Control thisPage)

and then calling it like this in pageload:
 Class1.showRadEditor(PlaceHolder1);

If you have a better solution let me know.

regards,
John


Tags
Editor
Asked by
John Guinto
Top achievements
Rank 1
Answers by
Rumen
Telerik team
John Guinto
Top achievements
Rank 1
Share this question
or