Creating DNN Text Editor programatically
I have a lot of question from people who asking me about "How to create DotNetNuke Text Editor programmatically". DNN module developer are confuse to do that because there is no documentation about it. Honestly .. not yet. :)
So far, the easiest way is to do like this :
DotNetNuke.UI.UserControls.TextEditor te = new DotNetNuke.UI.UserControls.TextEditor();
te.Width = Unit.Pixel(400);
te.Height = Unit.Pixel(200);
te.Text = "this is some text";
ph1.Controls.Add(te);
Note: ph1 is PlaceHolder control. The DotNetNuke Text Editor will be injected to PlaceHolder and then set it's properties.
But if you do that, you will receive this message : "object not set to an instance of an object"
Even if you use this technique :
UserControl uc = (UserControl)this.LoadControl("~/controls/texteditor.ascx");
DotNetNuke.UI.UserControls.TextEditor te = (DotNetNuke.UI.UserControls.TextEditor)uc;
te.Width = Unit.Pixel(400);
te.Height = Unit.Pixel(200);
te.Text = "this is some text";
ph1.Controls.Add(te);
You will receive same error message which indicating that the object is not set to an instance of an object.
If you search across DotNetNuke forums or from forums.asp.net, you will got - almost - no answer (or maybe hard to find the solution).
Actually, the answer is simple. You can do it with two lines of code. Watch me.
DotNetNuke.UI.WebControls.DNNRichTextEditControl te = new DotNetNuke.UI.WebControls.DNNRichTextEditControl();
te.Value = "this is some text";
ph1.Controls.Add(te);
The solution is ... use DotNetNuke.UI.WebControls instead of DotNetNuke.UI.UserControls !
It's more easier and make your headache gone forever. :)
Cheer !