使用ckeditor无法显示存储数据而无需使用标记

时间:2016-05-26 17:18:53

标签: c# asp.net ckeditor

我使用ckeditor在页面上存储多个数据元素,以允许富文本和从Work / Excel剪切/粘贴。数据与所有HTML标签一起保存,但是我似乎无法将这些数据显示在没有标签的页面上并返回到html格式的内容。

知道这一定很简单,但我花了大半天的时间试图找出它并没有快乐。

一个例子 正在保存的数据:第4行带有粗体斜体

页面上显示的数据:

<p>Stem #4 with some <strong>bold </strong>font and<em> italics</em></p> 

我使用标签输出数据:

 <td>
     <asp:Label ID="txt_Stem" runat="server" Text='<%#:Item.Stem %>' ></asp:Label>
 </td>

使用带有ckeditor的多行文本框进行输入:

<td><asp:TextBox ID="Stem" Columns="50" Rows="8" TextMode="MultiLine" runat="server" CssClass="ckeditor"></asp:TextBox>
           <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="* STEM Required" ControlToValidate="Stem" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator></td>

我已经设置了用ckeditor替换输出标签的脚本,但没有任何东西在触发并仍然获取所有的html标签。从Word或Excel剪切/粘贴数据时看起来更糟。

2 个答案:

答案 0 :(得分:0)

使用<asp:Literal>代替<asp:Label>并将其Mode属性设置为PassThrough

<td>
    <asp:Literal ID="txt_Stem" runat="server" Text='<%#:Item.Stem %>' Mode="PassThrough"></asp:Literal>
</td>

标签控件会发送HTML编码文本,因此,如果您在浏览器中查看页面来源,则会看到&lt而不是<。文字控件允许您“按原样”将文本发送到浏览器。

请注意,发送原始文本而不进行编码或过滤是一种安全风险(XSS),因为它允许恶意用户潜在地发送最终存在于用户浏览器中的恶意代码。

答案 1 :(得分:0)

结束我必须做的所有工作才能改变这一点:

<asp:Label ID="txt_Stem" runat="server" Text='<%#:Item.Stem %>' ></asp:Label>

对此:

<asp:Label ID="txt_Stem" runat="server" Text='<%# Item.Stem %>' ></asp:Label>

&lt;%#之后的冒号完全不同了。