Wednesday, June 10, 2009

How to add a Custom Button on TopToolBar of HTML Editor

As to the new AjaxControlToolkit control HTML Editor, if some one wants to add a custom button onto TopToolBar of Editor and do some custom code, you can add a MethodButton and define client-side onclick to do script. It's no way to define server-side onclick of it. However, you can build a doPostBack functionality on client if you'd like to do onclick on the server-side.


public class CustomEditor : AjaxControlToolkit.HTMLEditor.Editor
{
public CustomEditor()
{
//
// TODO: Add constructor logic here
//
}


protected override void FillTopToolbar()
{
//base.FillTopToolbar();

AjaxControlToolkit.HTMLEditor.ToolbarButton.MethodButton btn=new AjaxControlToolkit.HTMLEditor.ToolbarButton.MethodButton();
btn.NormalSrc= "aa.jpg";
btn.Attributes.Add("onclick", "alert('a');");
TopToolbar.Buttons.Add(btn);

}
}


Update:

This new feature has been added to Editor control. You can download it and create custom button in editor control:

http://ajaxcontroltoolkit.codeplex.com/SourceControl/changeset/view/54501

9 comments:

Unknown said...

Hi, thank you so much for this article. I wanna creat a custom button to insert a string of html into the content, I know in Obout HtmlEditor, it has a client side api “InsertHtml()”, could you please tell how to realize this with ajax html editor ?

Anonymous said...

See how to add "correctly" custom buttons here: http://forums.asp.net/p/1432800/3227409.aspx#3227409

Vince Xu said...

Thanks for that new feature.

Anonymous said...

Thank you so much for this article.
___________________

Vince

Your movies on demand

Custom Paper Writing said...

Many institutions limit access to their online information. Making this information available will be an asset to all.

Gabriel McAdams said...
This comment has been removed by the author.
Gabriel McAdams said...

I just added a tip to my blog showing how to set the default state of the editor's toolbar buttons. http://www.thecodepage.com/post/Change-the-default-state-of-an-AJAXControlToolkit-HTMLEditor-Toolbar-Button.aspx

SocialLiberal said...

I put this code into my project, but it doesn't appear to do anything.

Perhaps you can elaborate on how we're supposed to use this code?

crookedalley said...

Really i impressed. What a wonderful presentation.Now i am happy.Thank You