我目前正在使用 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?
发布评论
评论(2)
Erik 提供的解决方案不适用于包含属性值的表标签。例如:
将不会被解码。我还发现标签也由
HTMLEditorExtender
编码。更简单的解决方案是使用
Server.HTMLDecode()
方法。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 theHTMLEditorExtender
as well.The easier solution is to use the
Server.HTMLDecode()
method.我有同样的问题,这似乎与扩展程序对 HTML 内容执行的默认清理有关。我还没有找到关闭它的方法,但解决方法非常简单。
编写一个反清理函数,用适当的标签替换已清理的标签。下面是我用 VB.Net 编写的。 AC# 版本看起来非常相似:
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: