在AJAX.NET中使用FCKEditor不能读取FCKEditor内容的解决方法
aspx文件如下:
<%@ Page Language="C#" MasterPageFile="~/Blog/Blogger/Admin/Admin.Master" ValidateRequest="false" AutoEventWireup="true" CodeBehind="AddArticle.aspx.cs" Inherits="Blog.Blogger.Admin.Article.AddArticle" Title="Blog" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="phBody">
<form id="MainForm" runat="server">
<script language="javascript"> function FCKUpdateLinkedField(id) { try { if(typeof(FCKeditorAPI) == "object") { FCKeditorAPI.GetInstance(id).UpdateLinkedField();
}
}
catch(err) { }
} </script>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="True"> </asp:ScriptManager> <asp:Panel ID="updating" runat="server" BorderWidth="0" BorderStyle="solid" style="z-index: 1;">
<asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> <DIV style="BORDER-RIGHT: #dcbe6e 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #dcbe6e 1px solid; PADDING-LEFT: 5px; BACKGROUND: #ffffbf; LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: #dcbe6e 1px solid; WIDTH: 218px; BOTTOM: 5px; PADDING-TOP: 5px; BORDER-BOTTOM: #dcbe6e 1px solid; POSITION: absolute"> <IMG alt="??¨¦?o¨°" src="/Blog/Blogger/Admin/Album/Images/loading.gif" />¨¨???¡À¡ê¡ä??D,??¨¦?o¨°<input type="button" id="abortButton" onclick="cancelRequest()" value="¨¨???" /> </DIV> </ProgressTemplate> </asp:UpdateProgress>
</asp:Panel>
…
<asp:UpdatePanel ID="upAutoSave" runat="server">
<ContentTemplate>
<%if ((int)Session["Blogger_SavePostID"] != 0){ %>
<img src="/Blog/Blogger/Images/hasSaved.jpg" />
<span>日志已自动保存</span>
<%} %>
<asp:Timer ID="tmr" runat="server" Interval="20000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<div style="width: 698px; height: 346px">
<FCKeditorV2:FCKeditor id="Content" runat="server" Width="100%" BasePath="~/FCKeditor/" Height="500px" ToolbarSet="Default"></FCKeditorV2:FCKeditor>
</div>
…
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="phBody">
<form id="MainForm" runat="server">
<script language="javascript"> function FCKUpdateLinkedField(id) { try { if(typeof(FCKeditorAPI) == "object") { FCKeditorAPI.GetInstance(id).UpdateLinkedField();
}
}
catch(err) { }
} </script>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="True"> </asp:ScriptManager> <asp:Panel ID="updating" runat="server" BorderWidth="0" BorderStyle="solid" style="z-index: 1;">
<asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> <DIV style="BORDER-RIGHT: #dcbe6e 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #dcbe6e 1px solid; PADDING-LEFT: 5px; BACKGROUND: #ffffbf; LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: #dcbe6e 1px solid; WIDTH: 218px; BOTTOM: 5px; PADDING-TOP: 5px; BORDER-BOTTOM: #dcbe6e 1px solid; POSITION: absolute"> <IMG alt="??¨¦?o¨°" src="/Blog/Blogger/Admin/Album/Images/loading.gif" />¨¨???¡À¡ê¡ä??D,??¨¦?o¨°<input type="button" id="abortButton" onclick="cancelRequest()" value="¨¨???" /> </DIV> </ProgressTemplate> </asp:UpdateProgress>
</asp:Panel>
…
<asp:UpdatePanel ID="upAutoSave" runat="server">
<ContentTemplate>
<%if ((int)Session["Blogger_SavePostID"] != 0){ %>
<img src="/Blog/Blogger/Images/hasSaved.jpg" />
<span>日志已自动保存</span>
<%} %>
<asp:Timer ID="tmr" runat="server" Interval="20000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<div style="width: 698px; height: 346px">
<FCKeditorV2:FCKeditor id="Content" runat="server" Width="100%" BasePath="~/FCKeditor/" Height="500px" ToolbarSet="Default"></FCKeditorV2:FCKeditor>
</div>
…
在AJAX.NET 调用Callback方法 的时候,用Content.Value是取不到值的,这是由于在 Callback 时没有调用 FCK.UpdateLinkedField() 方法。在窗体的Load 事件注册一下该方法:protected void Page_Load(object sender, EventArgs e)之后就可以使用Content.Value 获得FCKeditor 的值了。
{
if (!IsPostBack)
{
Page.ClientScript.RegisterOnSubmitStatement(
Content.GetType(),
"editor",
"FCKUpdateLinkedField('" + Content.ClientID + "');");
可以参考:ASP.NET下解决FCKEditor在AJAX中取值问题
FCK Wiki