Radeditor Attributes.Add KeyUp issue

2 posts, 0 answers
  1. Matt
    Matt avatar
    12 posts
    Member since:
    May 2009

    Posted 26 Oct 2011 Link to this post

    I have a radeditor control inside an asp.net form view insert item template.

     As the user types text into the radeditor, I want to display the text/html inside a seperate label (within the same insert item template) in real time. (Yes, I know that the radeditor has a preview mode, but the real time preview must be seperate to the radeditor in my scenario). 

    This is my server side code:
    RadEditor re1 = (RadEditor)FormView_RISummaryDetailsFV.FindControl("RadEditorSummaryDescription_RISummaryDetailsFVEditItemTemplate");
    Label lab1 = (Label)FormView_RISummaryDetailsFV.FindControl("LabelResumePreviewHeader_RISummaryDetailsFVEditItemTemplate");
    Label lab2 = (Label)FormView_RISummaryDetailsFV.FindControl("LabelResumePreviewContents_RISummaryDetailsFVEditItemTemplate");
     
     
    re1.Attributes.Add("onKeyUp", "JavaScript:summaryRealTimePreview('" + re1.ClientID + "', '" + lab1.ClientID + "', '" + lab2.ClientID + "');");

    This is my JavaScript code:
    <script type="text/javascript" >
        function summaryRealTimePreview(re1_id, lab1_id, lab2_id) {
            var re1 = $find(re1_id);
            var lab1 = document.getElementById(lab1_id);
            var lab2 = document.getElementById(lab2_id);
     
     
            lab1.innerHTML = re1.get_html();
            lab2.innerHTML = re1.get_html();
        }
    </script>


    Also, I have attempted to implement the onClientLoad="onClientLoad" function of the RadEditor control, but I am unable to find the two required labels which are both inside the insert item template, such as:

    <telerik:RadEditor ID="RadEditor1" runat="server" onClientLoad="OnClientLoad" />

    <script language="javascript" type="text/javascript">
        function OnClientLoad(editor) {
            var element = document.all ? editor.get_document().body : editor.get_document();
            $telerik.addExternalHandler(element, "keyup", keyUpFunction);
        }
     
     
        function keyUpFunction() {
            alert("key up function tripped");
        }
    </script>





    Can anyone guide me on the correct syntax or correct coding to achieve this?





    .
  2. Rumen
    Admin
    Rumen avatar
    14372 posts

    Posted 27 Oct 2011 Link to this post

    Hi Matt,

    This server code will not work re1.Attributes.Add("onKeyUp" because you can attach to the client events of RadEditor's content area only on the client. You can see how to attach to the keyup event of RadEditor in the following article: attachEventHandler.

    For example, you can pass the IDs of the label controls to the client from the server using HiddenFields, but this is a general knowledge question which is out of the scope of Telerik support.

    All the best,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top