Quantcast
Channel: AjaxControlToolkit Work Item Rss Feed
Viewing all articles
Browse latest Browse all 4356

Created Issue: HtmlEditorExtender encoding HTML in postback when using LoadControl() [27170]

$
0
0
I found a case where the HtmlEditorExtender is encoding the HTML during a postback when it's in a user control that is loaded onto a page using LoadControl().

To reproduce, create a user control with a text box, an HtmlEditorExtender, and a button. Create a web page and in the Page_Load event, use LoadControl() to load the user control.

If you load or enter formatted text into the text box, for example "<p>test</p>" and click the button to post the page, the text is replaced with "&lt;p&gt;test&lt;/p&gt;". Clicking the button again, further encodes that and replaces it with "&amp;lt;p&amp;gt;test&amp;lt;/p&amp;gt;". This gets further encoded each postback.

I confirmed that this does not happen if I add the user control at design time to the page, only if I use LoadControl() to load it.

I have spent days trying to resolve this issue, but I just can't tell if I am doing something wrong, if the control is simply incompatible with this scenario, or if there is a reliable workaround.

Here is some code to reproduce the issue:

User control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestDynamicRichTextControl.ascx.cs" Inherits="Sample.forms.TestDynamicRichTextControl" %>
<asp:TextBox ID="txtBody" runat="server" Columns="80" Rows="15" TextMode="MultiLine"></asp:TextBox>
<ajaxToolkit:HtmlEditorExtender ID="heeBody" runat="server"
TargetControlID="txtBody">
<Toolbar>
<ajaxToolkit:Bold />
<ajaxToolkit:Italic />
<ajaxToolkit:Underline />
</Toolbar>
</ajaxToolkit:HtmlEditorExtender>
<br />
<asp:Button ID="btnTestPartialPostback" runat="server" Text="Test Partial Postback" onclick="btnTestPartialPostback_Click" />
<asp:Label ID="lblResult" runat="server"></asp:Label>

User control code (BaseUserControl extends System.Web.UI.UserControl and declares Initialize() ) :

public partial class TestDynamicRichTextControl : BaseUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}

public override void Initialize()
{
txtBody.Text = "<p>This is a test</p>";
}

protected void btnTestPartialPostback_Click(object sender, EventArgs e)
{
lblResult.Text = DateTime.Now.ToString();
}
}

The main page contains this placeholder:

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>


The code of the main page:

public partial class TestDynamicControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PlaceHolder1.Controls.Clear();
BaseUserControl formUc = (BaseUserControl)this.LoadControl("forms/TestDynamicRichTextControl.ascx");
PlaceHolder1.Controls.Add(formUc);

if (!IsPostBack)
formUc.Initialize();
}
}


Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>