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">
</ajaxToolkit:HtmlEditorExtender>

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

<configSections>

<sectionGroup name="system.web">

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

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

</sectionGroup>

</configSections>

<runtime>

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

<dependentAssembly>

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

<bindingRedirect oldVersion="0.0.0.0-1.4.6.0" newVersion="1.4.6.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>

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

<providers>

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

</providers>

</sanitizer>




Then The Result is