Saturday, May 25, 2013

HtmlEditorExtender (ASP 4.5)

This Tutorial  about using HtmlEditorExtender in your aspx pages.
Frst of all  HtmlEditorExtender  can be added as extender for a regular textbox control for example :

<asp:TextBox ID="txtMessageBody" runat="server" TextMode="MultiLine" Rows="10" Width="100%"></asp:TextBox>
<ajaxToolkit:HtmlEditorExtender ID="txtMessageBody_HtmlEditorExtender" runat="server" Enabled="True" TargetControlID="txtMessageBody">

but if you try to run your web site the following error will be appeared  : 
"Sanitizer provider is not configured in the web.config file. If you are using the HtmlEditorExtender with a public website then please configure a Sanitizer provider. Otherwise, set the EnableSanitization property to false."

So you have two choices to solve it  : 
First choice :
If your page is not public you can set the EnableSanitization property to false in your HtmlEditorExtender

Second Choice :
  1. Add "HtmlAgilityPack.dll" and  "SanitizerProviders.dll" in your "Bin" Folder
  2. Add The following in Your Web.Config file :
Under Configuration tag  add


<sectionGroup name="system.web">

<section name="sanitizer" requirePermission="false"

type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit" />




<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">


<assemblyIdentity name="HtmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral" />

<bindingRedirect oldVersion="" newVersion="" />




Under System.Web  tag add 
<sanitizer defaultProvider="HtmlAgilityPackSanitizerProvider">


<add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"></add>



Then The Result is