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

How to get the RadEditor selectedText/Content in .CS file

1 Answer 115 Views
Editor
This is a migrated thread and some comments may be shown as answers.
vikram
Top achievements
Rank 1
vikram asked on 24 Mar 2009, 01:25 PM
Hi,
I am using RadEditor in my web application, in which i have to save the selected text or content in the database.
But  I am not getting the selected Text or content in .cs file.
My code is below:

The HTML is: 

<form id="form1" runat="server"> 

 

<asp:ScriptManager ID="ScriptManager" runat="server"> </asp:ScriptManager 

 

<telerik:RadScriptBlock ID="scriptBlock" runat="server">  

 

<script type="text/javascript"> 

 

function setIntoTextBox( selection)

 

   var hide=$find("<%=txtSharedContent.ClientID %>");  

hide.set_value(

selection );  

 

 

 

return true;

}

 

RadEditorCommandList[

"SaveContent"] = function(commandName, editor, oTool)  

 

 

{  

 

var editor = $find("<%=radEditor.ClientID%>") ; 

 

var selection = editor.getSelectionHtml();  

 

if(selection)  

{

setIntoTextBox(selection);

editor.pasteHtml(

'<span style="background-color:Yellow" >' + selection + '</span>');  

 

 

 

var ajaxManager = $find("<%= ajaxManager.ClientID %>");
ajaxManager.ajaxRequest(
"SaveContent");  

 

 

else  

 

{

alert(

'Please select the sentence);  

 

 

} }; 

 

</script 

</

 

telerik:RadScriptBlock>  

 

 

<

 

telerik:RadAjaxManager ID="ajaxManager" runat="server" DefaultLoadingPanelID="ajaxLoadingPanel" EnableAJAX="true" OnAjaxRequest="AjaxRequest"  

 

 

<AjaxSettings 

 

<telerik:AjaxSetting AjaxControlID="ajaxManager">  

 

<UpdatedControls

 

<telerik:AjaxUpdatedControl ControlID="radEditor"> 

 

 

</telerik:AjaxUpdatedControl 

 

<telerik:AjaxUpdatedControl ControlID="txtSharedContent">  

 

</telerik:AjaxUpdatedControl 

 

</UpdatedControls> 

 

</telerik:AjaxSetting 

 

</AjaxSettings 

 

</telerik:RadAjaxManager 

 

<telerik:RadTextBox ID="txtSharedContent" runat="server" />  

 

<telerik:RadEditor ID="radEditor" runat="server" EditModes="All" ToolbarMode="default"  

 

<Languages 

 

<telerik:SpellCheckerLanguage Code="en-US" Title="English" />  

 

</Languages

 

<Tools  

 

 

<telerik:EditorToolGroup  

 

<telerik:EditorTool Name="SaveContent" Text="Save Content" /> 

 

</telerik:EditorToolGroup 

 

</Tools 

 

</telerik:RadEditor 

 

</form>

 

 



The .cs code is

using 

 

System;
using System.Data;  

 

using 

 

System.Configuration;  

 

 

using System.Collections;  

 

using  System.Web;  

 

using  System.Web.Security; 

 

 

using System.Web.UI;

 

 

 

using System.Web.UI.WebControls;

 

 

 

using System.Web.UI.WebControls.WebParts;

 

 

 

using System.Web.UI.HtmlControls;

 

 

 

using Telerik.Web.UI;

 

 

 

using System.Collections.Generic;

 

 

 

using System.Text;

 

 

public partial class NewEditor : System.Web.UI.Page

 

 

 

protected void Page_Load(object sender, EventArgs e)

 { 

 

if (!IsPostBack)

 {
radEditor.Content =

"<span><P>Another week closer to the end of a year everyone will be very glad to see the back of, for the record the NZX50 closed modestly down for the week, -22 at 2,655. Large cap stocks mainly led the way this week, with APN, The Warehouse, Air NZ, Contact Energy and Vector comprising the five strongest performers whilst the bottom end of the field was a rather unseemly race down between Pyne Gould Wrightsons and its progeny, NZ Farming Systems.<br/><br/></span>";

 

 }

}

 

 

protected void AjaxRequest(object sender, AjaxRequestEventArgs e)

 { 

 

switch (e.Argument)

 {

 

 

case "SaveContent"

 

 

//Here I want to get the selected Text.
string
str = txtSharedContent.Text;

 

break;  

 

}

}

}

 


So how i can get the selected Text or Content in .cs file?



Thanks/Regards
Vikram


1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Mar 2009, 09:49 AM
Hi Vikram,

Your code is fine and it works as expected on my side. You can see my test in the attached video as well as test my project. Am I missing something?

Another way to obtain the selected value is to put a hidden field and obtain its value on the server after the ajax callback.

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
vikram
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or