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

How to get the current EditMode of a RadEditor control on button click on client side

1 Answer 57 Views
Editor
This is a migrated thread and some comments may be shown as answers.
sandeep
Top achievements
Rank 1
sandeep asked on 04 Aug 2014, 07:39 PM
I want to get the current edit mode(Html,Design) of a rad Editor control as an alert ,on button click control.And i want to set rad-editor control same mode even after the post back on button click.

i.e if the mode of a rad-editor control is (HTML),i want the rad-editor to be in same mode (HTML)even after  post-back (buttonclick)

Thanks
Sandeep 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 05 Aug 2014, 05:51 AM
Hi sandeep,

Please try the below sample code snippet to get the EditMode of a RadEditor from JavaScript. In order to achieve your second scenario try to set the currently selected EditMode in a hidden field and on postback call a client side method to set the mode as follows.

ASPX:
<telerik:RadEditor ID="reditorDemo" runat="server">
</telerik:RadEditor>
<telerik:RadButton ID="rbtnEditorMode" runat="server" Text="Get Editor Mode" OnClientClicked="getEditorMode">
</telerik:RadButton>
<asp:HiddenField ID="hiddenEdiorMode" runat="server" />

JavaScript:
function getEditorMode(sender, args) {
    var radEditor = $find("<%=reditorDemo.ClientID%>");
    modeType = radEditor.get_mode(); //editmode type
    document.getElementById("hiddenEdiorMode").value = modeType; // assigning edit mode value to hidden field
    switch (modeType) {
        case 1: alert("Design"); break;
        case 2: alert("Html"); break;
        case 4: alert("Preview"); break;
    }
}
function changeMode(mode) {
    //setting edit mode value after postback
    var editor = $find("<%=reditorDemo.ClientID %>");
    editor.set_mode(mode);
}

C#:
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        //on postback will call client side method and passing the currently selected edit mode
        string script = "function f(){changeMode('" + hiddenEdiorMode.Value + "'); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
    }
}

Thanks,
Shinu.
Tags
Editor
Asked by
sandeep
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or