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

2 posts, 0 answers
  1. sandeep
    sandeep avatar
    17 posts
    Member since:
    May 2014

    Posted 04 Aug 2014 Link to this post

    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 
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Aug 2014 in reply to sandeep Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top