2012-10-23 57 views
0

在我的aspx,我有下面的代碼片段,它正確地從AjaxToolkitAJAX Control Toolkit的控件編輯器的Javascript訪問

<div> 
    <ajaxToolkit:Editor ID="Editor" runat = "server" /> 
</div> 

渲染編輯器控件在C#中,訪問編輯的內容是根本:

Editor.Content = "some text here" 

但是在JavaScript中,我不確定如何訪問它。到目前爲止,我已經嘗試過:

var st =$find('<%=Editor.ClientID%>').get_content(); 

但是$ find語句返回一個空值。

回答

1

它應該工作。我嘗試了下面的代碼,編輯器組件被成功發現。

<asp:ScriptManager runat="server" ID="ScriptManager" EnablePartialRendering="true"> 
    <Scripts> 
     <asp:ScriptReference Path="Scripts/jquery-1.4.1.js" /> 
    </Scripts> 
</asp:ScriptManager> 

<div> 
    <ajax:Editor runat="server" ID="Editor"></ajax:Editor> 
</div> 

<script type="text/javascript"> 
    Sys.Application.add_load(function() { 
     Sys.Debug.traceDump($find('<%= Editor.ClientID %>'), "editor"); 
    }); 

</script> 

因此,嘗試在Sys.Application.add_load事件處理程序中訪問您的編輯器。如果這能幫助你,那麼問題的原因是你在頁面完成組件初始化之前試圖找到組件。

0

使用此功能玩弄後,我注意到,HTML看起來像這樣:

<iframe id = "Some iFrameId"> 
    #document 
    <html> 
     <head>...</head> 
     <body>The text of the editor</body> 
    </html> 
</iframe> 

在ASPX,我做了以下使我的生活痘痘更容易一點:

<div id ="myDiv" ClientIDMode="Static"> 
    <ajaxToolkit:Editor ID="Editor" runat = "server" /> 
</div> 

通過這樣做,我簡化了我的問題,以便找到包含在編輯器的HTML myDiv中的iFrame。

要做到這一點的JS

//get the iFrame 
var myIframe = $("#myDiv, iframe") //this returns an array and myIframe[1] is the iFrame, which contains the text. 
//get the HTML from the iFrame 
var content = myIFrame[1].contentWindow.document.body.innerHTML; 

現在內容包含,我一直在尋找。這是很長的,可能有一個更簡單的方法,但在尋找解決方案後,我發現其中大部分是:

做一個.get_content或某個函數調用,這對我的情況不起作用。

相關問題