Thought I would share this. I am a DNN developer and wanted to be able to use the FCKEditor built into DNN. I also didn't want to have an external ascx file, just a single control that could be compiled into a DLL. Below is the VB code for using the DNN FCKEditor and having the data post back with a GAIA button. I enhanced the previous code that was posted, and still need to add some checking into it for other editor types, but it does work.
Imports System
Imports System.ComponentModel
Imports System.Globalization
Imports System.Reflection
<Assembly: Web.UI.WebResource("YourNamespace.getElement.js", "text/javascript")>
Namespace Controls
Public Class TextEditor : Inherits Gaia.WebWidgets.Panel
Private gSaveControl As System.Web.UI.Control
Public Property Text() As String
Get
EnsureChildControls()
Return Me.TransferField.Value
End Get
Set(ByVal value As String)
Me.Editor.Value = value
Me.ForceAnUpdate()
End Set
End Property
Public ReadOnly Property Editor() As DotNetNuke.UI.WebControls.DNNRichTextEditControl
Get
Return CType(Me.FindControl("Editor"), DotNetNuke.UI.WebControls.DNNRichTextEditControl)
End Get
End Property
Public ReadOnly Property TransferField() As Gaia.WebWidgets.HiddenField
Get
Return CType(Me.FindControl("TransferField"), Gaia.WebWidgets.HiddenField)
End Get
End Property
Public Property SaveControl() As System.Web.UI.Control
Get
Return gSaveControl
End Get
Set(ByVal value As System.Web.UI.Control)
gSaveControl = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
EnsureChildControls()
End Sub
Protected Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
Dim TransferField As New Gaia.WebWidgets.HiddenField()
'Dim Editor As DotNetNuke.UI.UserControls.TextEditor = CType(Me.Page.LoadControl("~/controls/texteditor.ascx"), DotNetNuke.UI.UserControls.TextEditor)
Dim Editor As New DotNetNuke.UI.WebControls.DNNRichTextEditControl()
TransferField.ID = "TransferField"
Editor.ID = "Editor"
Editor.Width = Me.Width
Editor.Height = Me.Height
Me.Controls.Add(TransferField)
Me.Controls.Add(Editor)
End Sub
Protected Overrides Sub IncludeScriptFiles()
MyBase.IncludeScriptFiles()
Gaia.WebWidgets.Manager.Instance.AddInclusionOfFileFromResource("RefSchedules.Common.getElement.js", GetType(TextEditor), "TextEditorgetElementFinishedLoading")
End Sub
Private Sub TextEditor_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim InternalEditor As System.Web.UI.Control = Me.Editor.FindControl("Editoredit")
If InternalEditor.GetType() Is GetType(DotNetNuke.HtmlEditor.FckHtmlEditorProvider.Fckeditor) Then
Dim FCKEditor As DotNetNuke.HtmlEditor.FckHtmlEditorProvider.Fckeditor = CType(Me.Editor.Controls(0), DotNetNuke.HtmlEditor.FckHtmlEditorProvider.Fckeditor)
Dim functionName As String = "getElement('" + Me.TransferField.ClientID & "').value = FCKeditorAPI.GetInstance('" + FCKEditor.ClientID & "').GetHTML();"
Dim Prop As PropertyInfo = SaveControl.GetType().GetProperty("OnClientClick")
If Prop IsNot Nothing Then
Prop.SetValue(SaveControl, functionName, Nothing)
Else
Throw New Exception("The SaveControl has not been set")
End If
End If
End Sub
End Class
End Namespace
Content of YourNamspace.getElement.js file:
function getElement(id) {
var object = null;
if( document.layers) { object = document.layers[id]; }
else if( document.all) { object = document.all[id]; }
else if(document.getElementById) { object = document.getElementById(id); }
return object;
}
TextEditorgetElementFinishedLoading = true;
I made several changes to the code. There was a problem when the editor is popup dynamically, the control would not work. The above code does work just fine during a dynamically created popup control such as a window. I also learned quite a bit about how to create Gaia controls with some more specific client side functionality. I will be posting a blog/tutorial on that when I get some time. You should be able to modify the above code slightly so that it will work with the non-DNN FCKEditor and shouldn't take much to do that. This is much cleaner than my previous posted code.
One of the other things that I added is a simple reflection function that will check to see if the Property OnClientClick is part of the SaveControl and if so, it will attach it. That removed several lines of code and the need to check every single type of control that you wanted it to work with.
Let me know what you guys think of this new version!
Chaitanya