ARTICLE

Customizing Editor Control of Ajax

Posted by Dipa Ahuja Articles | AJAX in C# June 14, 2010
In this article we will see how to customize editor control of Ajax.
Reader Level:
Download Files:
 

Ajax release the html editor control in May 13 2009 release. We found the Ajax's editor control in the Ajax toolkit. This provides the html enabled editor to write into it.

This control looks like this at the runtime

1.gif
 

As you can see there are lots of tools available in the editor. But sometime we require only few tools to be displayed in this editor. For that we can change the editor and override FillTopToolbar() and  FillBottomToolbar() methods of editor control.

For that in the App_code folder we have to add one .cs file. And then add the namespace AjaxControlToolkit.HTMLEditor

protected override void FillBottomToolbar()
{
    BottomToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.DesignMode());
    BottomToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.PreviewMode());
    BottomToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.HtmlMode());
}
protected override void FillTopToolbar()
{
    TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold());
    TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Italic());
}

As you can see here in the bottom toolbar we have added all three modes that is design, preview and html. But from the top we just add bold and italic.

So at run time this will look like: 

2.gif
 
We can use this control in asp.net page same as we use the usercontrol.

<%@ Register namespace="MyControls" tagprefix="custom" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <cc1:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
   <custom:CustomEditor ID="CustomEditor1"
    Width="500px" Height="200px" runat="server" />
        </div>
    </form>
</body>
</html>

Here the MyControls is the namespace that we use in .cs file of customEditor. And to use it in the cs of this aspx page we use the namespace 

using MyControls;
protected void Page_Load(object sender, EventArgs e)
{
    CustomEditor1.Content = "hello.. this is custome editor...";
}

Login to add your contents and source code to this article
post comment
     

can you please tell me how can upload image in editor?

Posted by waqas memon Aug 15, 2011

i think u cant add button, u can customize the editor bt cant add extra.. you can use/add button seperately..

Posted by Dipa Ahuja Feb 19, 2011

on editor i need to add button (to browse image)so when click on this button will open to me popup which have my desired design to browse image by url or by file uploder so how can i add this button on editor toolbar plz send to me on barby_sw@yahoo.com

Posted by barby sw Feb 17, 2011

thank's it helped me lot in my project work THANK U VERY MUCH

Posted by anant kolvankar Feb 16, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.