This is a migrated thread and some comments may be shown as answers.

[Solved] Cannot get Client-Side RadEditor edited text in a [runat=server] control via code-behind

1 Answer 181 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Sittha Apasirikul
Top achievements
Rank 1
Sittha Apasirikul asked on 23 Feb 2010, 08:17 AM
I use RadEditor to edit text in a span (SPAN2) which has runat=server attribute by click on an ImageButton and load current text into RadEditor in a RadWindow and edited it. When I click submit button on RadWindow , the text display in this page is changed. But when I click Button1 to load edited text in SPAN2 into a literal (Literal1) , the Text displayed in Literal1 is not the text I edited but it display old text which declared in ASPX instead.

How to get the edited text to display in Literal1 ? I want to use edited text via code-behind.

this is my code ..

Main.aspx
<%@ Page language="c#" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<script runat="server"
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        Literal1.Text = SPAN2.InnerHtml; 
    } 
</script> 
<html xmlns="http://www.w3.org/1999/xhtml"
    <head> 
        <title>Name</title> 
    </head> 
    <body> 
        <form id="Form1" method="post" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
            <Windows> 
                <telerik:RadWindow runat="server" ID="Editor" Width="700px" Height="550px" /> 
            </Windows> 
        </telerik:RadWindowManager> 
            <script type="text/javascript"
            var elementToEdit = null
            var oWnd = null;             
            function OpenWin(elemId) 
            { 
               elementToEdit = document.getElementById(elemId); 
               oWnd = radopen("Editor.aspx", "Editor"); 
            }        
            function WindowClose() 
            { 
               var oManager = GetRadWindowManager(); 
               var oWnd = oManager.GetWindowByName("Editor"); 
               oWnd.Close(); 
            }    
            </script> 
        <asp:UpdatePanel ID="UpdatePanel1" runat="server"
        <ContentTemplate> 
            <span id="SPAN2" runat="server" style="border:1px solid red;">Some sample text 1</span> 
            <asp:ImageButton ID="btnEdit2" runat="server" ImageAlign="AbsMiddle" ImageUrl="btn_textedit.png"  
            AlternateText="Edit" CausesValidation="false" OnClientClick="OpenWin('SPAN2'); return false;" /> 
        </ContentTemplate> 
        </asp:UpdatePanel>       
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
        <br /> 
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>         
        </form> 
    </body> 
</html> 

Editor.aspx

<%@ Page language="c#" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html> 
    <head> 
        <title>Edit Text</title> 
    </head> 
    <body> 
        <form id="Form1" method="post" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <script type="text/javascript"
            function OnClientLoad (editor)           
            { 
                var oElement = window.parent.elementToEdit; 
                if (oElement) 
                {        
                    editor.set_html(oElement.innerHTML); 
                } 
                editor.add_submit(function () 
                { 
                    var oElement = window.parent.elementToEdit; 
                    if (oElement) 
                    {                    
                        oElement.innerHTML = editor.get_html(true); 
                    }                    
                    window.parent.WindowClose(); 
                    return false;        
                }); 
            } 
        </script> 
        <telerik:RadEditor ID="editor1" OnClientLoad="OnClientLoad" Runat="server"
        </telerik:RadEditor>   
        <input type="submit" value="Submit" /> 
        </form> 
    </body> 
</html> 
 

Thanks for your help.

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 25 Feb 2010, 03:17 PM
Hi Sittha,

I already answered your support ticket on the same subject. For convenience I am pasting my answer below:


This is not a problem with the RadEditor control but it is a general ASP.NET programming issue. Data is sent upon post back, only if it is in a form element - in order to save the content of the DIV you need to modify the ASPX file.

For your scenario I would suggest you to save the content of these DIVs in hidden fields and update them on load or when you modify the content with RadEditor.



Regards,
Dobromir
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Editor
Asked by
Sittha Apasirikul
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or