回发表上的 AJAX HTMLEditorExtender 不显示

发布于 2024-12-16 02:07:56 字数 1138 浏览 2 评论 0 原文

我目前正在使用 Ajax 工具; HTMLEditorExtender 在 C# ASP.NET 项目中将文本框转换为所见即所得编辑器。在初始页面加载时,我将大量格式化文本和表格放入编辑器中,看起来不错;甚至桌子。

数据被加载到 asp:panel 中,面板中的项目/显示是实际加载到扩展器中并显示的内容。

但是,如果我想要一个按钮将编辑器中的所有数据保存到会话中,并且在按下按钮后仍然在页面回发的 WYSIWG 编辑器中显示所有内容,则加载到文本框中的所有内容都很好,除了桌子。他们想出了标签。这附近还有吗?

我用来初始加载页面的代码是这样的:

ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlContent.RenderControl(hw);
txtPN.Text = sb.ToString();
pnlContent.Visible = false;

在按钮上单击我已保存此内容:

string strHTMLText = txtPN.Text;
Session["ProgressNoteHTML"] = strHTMLText;

并且我将其加载到回发中,如下所示:

txtPN.Text = (string)Session["ProgressNoteHTML"];
ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
pnlContent.Visible = false;

关于为什么任何回发都会使标签出现在原始中的任何想法他们不加载页面吗?

I am currently using an Ajax tool; HTMLEditorExtender to turn a textbox into a WYSIWYG editor, in a C# ASP.NET project. On the initial page load I place a large amount of formated text and tables into the editor which appears fine; even the tables.

The data is loaded into an asp:panel and the items/display from the panel is what is actually loaded into the extender and displayed.

However, if I want to have a button that saves all of the data that is in the editor to a Session and after the button press still display everything in the WYSIWG editor on the page postback everything that loads in the the textbox is fine except for the tables. They come up with the tags. Is there anyway around this?

The code I am using to initially load the page is this:

ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlContent.RenderControl(hw);
txtPN.Text = sb.ToString();
pnlContent.Visible = false;

On the button click I am having this saved:

string strHTMLText = txtPN.Text;
Session["ProgressNoteHTML"] = strHTMLText;

And I am loading it on the postback like this:

txtPN.Text = (string)Session["ProgressNoteHTML"];
ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
pnlContent.Visible = false;

Any ideas as to why any postbacks would make the tags appear and in the original page load they do not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在风中等你 2024-12-23 02:07:56

Erik 提供的解决方案不适用于包含属性值的表标签。例如: 将不会被解码。我还发现 标签也由 HTMLEditorExtender 编码。

更简单的解决方案是使用 Server.HTMLDecode() 方法。

TextBox_Editor.Text = Server.HtmlDecode(TextBox_Editor.Text) 'fixes encoding bug in ajax:HTMLEditor

The solution offered by Erik won't work for table tags containing property values. For instance: <table align="right"> will not be decoded. I have also found that <img> tags are encoded by the HTMLEditorExtender as well.

The easier solution is to use the Server.HTMLDecode() method.

TextBox_Editor.Text = Server.HtmlDecode(TextBox_Editor.Text) 'fixes encoding bug in ajax:HTMLEditor
拒绝两难 2024-12-23 02:07:56

我有同样的问题,这似乎与扩展程序对 HTML 内容执行的默认清理有关。我还没有找到关闭它的方法,但解决方法非常简单。
编写一个反清理函数,用适当的标签替换已清理的标签。下面是我用 VB.Net 编写的。 AC# 版本看起来非常相似:

 Protected Function FixTableTags(ByVal input As String) As String
    'find all the matching cleansed tags and replace them with correct tags.
    Dim output As String = input

    'replace Cleansed table tags.
    output = output.Replace("<table>", "<table>")
    output = output.Replace("</table>", "</table>")
    output = output.Replace("<tbody>", "<tbody>")
    output = output.Replace("</tbody>", "</tbody>")
    output = output.Replace("<tr>", "<tr>")
    output = output.Replace("<td>", "<td>")
    output = output.Replace("</td>", "</td>")
    output = output.Replace("</tr>", "</tr>")

    Return output
End Function

I have the same problem, It seems to have something to do with the default sanitizing that the extension performs on the HTML content. I haven't found a way to switch it off, but the workaround is pretty simple.
Write an Anti-Sanitizing function that replaces the cleansed tags with proper tags. Below is mine written in VB.Net. A C# version would look very similar:

 Protected Function FixTableTags(ByVal input As String) As String
    'find all the matching cleansed tags and replace them with correct tags.
    Dim output As String = input

    'replace Cleansed table tags.
    output = output.Replace("<table>", "<table>")
    output = output.Replace("</table>", "</table>")
    output = output.Replace("<tbody>", "<tbody>")
    output = output.Replace("</tbody>", "</tbody>")
    output = output.Replace("<tr>", "<tr>")
    output = output.Replace("<td>", "<td>")
    output = output.Replace("</td>", "</td>")
    output = output.Replace("</tr>", "</tr>")

    Return output
End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文