2011-11-17 69 views
0

我目前正在使用Ajax工具; HTMLEditorExtender在C#ASP.NET項目中將文本框轉換爲WYSIWYG編輯器。在初始頁面加載時,我將大量格式化的文本和表格放入編輯器中,看起來不錯;甚至桌子。回發表上的AJAX HTMLEditorExtender不顯示

將數據加載到一個asp:面板中,面板上的項目/顯示是實際加載到擴展器中並顯示的內容。但是,如果我想要一個按鈕將編輯器中的所有數據保存到會話中,並且在按鈕按下後仍然在頁面上的所見即所得編輯器中顯示所有內容,並回發加載到文本框中的所有內容除了桌子以外都很好。他們拿出標籤。有沒有辦法解決?

我使用初始加載頁面的代碼是這樣的:

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; 

關於爲什麼任何回發將使標籤出現和在原點的任何想法al頁面加載他們不?

回答

0

我有同樣的問題,它似乎與擴展在HTML內容上執行的默認清理有關。我還沒有找到切斷它的方法,但是解決方法非常簡單。 編寫一個Anti-Sanitizing功能,用適當的標籤替換已清潔的標籤。下面是我用VB.Net編寫的。 C#版本看起來非常相似:

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("&lt;table&gt;", "<table>") 
    output = output.Replace("&lt;/table&gt;", "</table>") 
    output = output.Replace("&lt;tbody&gt;", "<tbody>") 
    output = output.Replace("&lt;/tbody&gt;", "</tbody>") 
    output = output.Replace("&lt;tr&gt;", "<tr>") 
    output = output.Replace("&lt;td&gt;", "<td>") 
    output = output.Replace("&lt;/td&gt;", "</td>") 
    output = output.Replace("&lt;/tr&gt;", "</tr>") 

    Return output 
End Function 
2

Erik提供的解決方案不適用於包含屬性值的表標記。例如:<table align="right">將不會被解碼。我還發現<img>標籤也由HTMLEditorExtender編碼。

更簡單的解決方案是使用Server.HTMLDecode()方法。

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