C# .NET - how to design html editor using asp.net+c#

Asked By chinna samy on 21-Oct-08 05:10 AM
how to design html editor using asp.net+c#

re - Web Star replied to chinna samy on 21-Oct-08 05:21 AM

HtmlEditor.cs

The component itself contains many different HTML elements, so the server control class is derived from CompositeControl. In addition, the class must implement the IScriptControl methods:

public class HtmlEditor : CompositeControl, IScriptControl

In CompositeControl, child controls are added in the CreateChildControls method:

protected override void CreateChildControls()
{
    ...

    CreateToolbars(...);

    this.Controls.Add(CreateHtmlArea());
    this.Controls.Add(CreateDesignArea());
    this.Controls.Add(CreateTabbar());
    this.Controls.Add(CreateUpdateArea());

    base.CreateChildControls();
}

To implement the IScriptControl interface, two callback methods are required. The first, GetScriptReferences, tells ScriptManager what related script file(s) to load and from where. For this server control, we have chosen to embed the HtmlEditor.js file in our assembly resources. We tell ScriptManager the full resource path and assembly name so that it can load it from there, simplifying deployment:

protected virtual IEnumerable<ScriptReference>
    GetScriptReferences()
{
    ScriptReference htmlEditorReference =
        new ScriptReference(
        "Winthusiasm.HtmlEditor.Scripts.HtmlEditor.js",
        "Winthusiasm.HtmlEditor");

    ...

    return new ScriptReference[] { htmlEditorReference, ... };
}

The second callback method, GetScriptDescriptors, "maps" properties in the client control(s) to properties in the server control. ScriptManager uses this information to set the appropriate values in the client control as part of its client-side creation:

protected virtual IEnumerable<ScriptDescriptor>

    GetScriptDescriptors()
{
    ScriptControlDescriptor descriptor =
        new ScriptControlDescriptor("Winthusiasm.HtmlEditor",
        this.ClientID);

    descriptor.AddProperty("htmlencodedTextID",
                            this.HtmlEncodedTextID);
    ...

    return new ScriptDescriptor[] { descriptor };
}

Although we have now implemented the IScriptControl methods, there are two remaining modifications to make so that the IScriptControl callbacks get called. First, OnPreRender must be modified to call RegisterScriptControl, as follows:

protected override void OnPreRender(EventArgs e)
{
    ...

    if (!this.DesignMode)
    {
        // Test for ScriptManager and register if it exists.

        sm = ScriptManager.GetCurrent(Page);

        if (sm == null)
            throw new HttpException(
            "A ScriptManager control must exist on the page.");

        sm.RegisterScriptControl(this);

        ...
    }

    base.OnPreRender(e);
}

Then Render must be modified to call RegisterScriptDescriptors:

protected override void Render(HtmlTextWriter writer)
{
    if (!this.DesignMode)
        sm.RegisterScriptDescriptors(this);

    base.Render(writer);
}
http://www.codeproject.com/KB/ajax/HtmlEditor.aspx

HTML editor - mv ark replied to chinna samy on 21-Oct-08 05:31 AM

Building your own HTML editor can be laborious & time-consuming. In case you want it to work on popular browsers, you would have to test on a variety of browsers & their versions. So I suggest that rather than building your own, take a look at these free HTML text editor controls that have good cross browser support:
Free Text Box - http://freetextbox.com/features/
FCKeditor - http://www.fckeditor.net/
TinyMCE - http://sourceforge.net/projects/tinymce/
http://tinymce.moxiecode.com/punbb/viewtopic.php?id=8141

FCKEditor & TinyMCE are open source.

They are extensively tested & as the last two are open source, you can tweak the code to customize.

read this link - C_A P replied to chinna samy on 21-Oct-08 05:44 AM

http://www.codeproject.com/KB/miscctrl/Dynamic_ASPNet_Control.aspx
read this link - C_A P replied to chinna samy on 21-Oct-08 05:45 AM
http://www.sitepoint.com/article/asp-dot-net-introduction/6/