OnTextChanged on radEditor

3 posts, 0 answers
  1. Ole Albers
    Ole Albers avatar
    25 posts
    Member since:
    Jun 2012

    Posted 04 Feb 2009 Link to this post

    Hi there.

    I got a problem that the OnTextChanged-Event from the radEditor does not work as expected. I got this following Code-Snippet:
          <asp:Label SkinID="mailLabel" ID="lblMailRcp"  runat="server"   Font-Bold="true"  Text="<%$Resources:TextResources, ID_MAIL_TO%>" />&nbsp;</td><td width="650"><telerik:RadTextBox OnTextChanged="anyText_TextChanged" ID="txtMailTo" Font-Size="10" runat="server"  ReadOnly="true" Width="100%"  AutoPostBack="true"></telerik:RadTextBox> 
     
            <telerik:RadEditor ID="EditorMailBody" runat="server" EditModes="Design" OnTextChanged="anyText_TextChanged"  AutoPostBack="true" 
                   Enabled="True" EnableResize="True" Language="de-DE"  
                   ToolsFile="~/App_GlobalResources/NoTools.xml" Visible="True"                 
                   Width="100%" Height="275" SkinID="EmailEditor"  
                   ><Content /></telerik:RadEditor> 

    This is within a RadAjaxPanel.

    Now my event-handler (opened by every radtextbox and the radeditor) looks this way:
    protected void anyText_TextChanged(object sender, EventArgs e) 
            { 
                if (sender is RadTextBox) 
                { 
                    RadTextBox selBox = (RadTextBox)sender; 
                    switch (selBox.ID) 
                    { 
                        case "txtMailTo"
                            _currentEmail.Recipient = selBox.Text; 
                            break
                        case "txtMailSubject"
                            _currentEmail.Subject = selBox.Text; 
                            break
                        case "lblMailSender"
                            _currentEmail.Sender = selBox.Text; 
                            break
                    } 
                } 
                else if (sender is RadEditor) 
                { 
                    RadEditor selBox = (RadEditor)sender; 
                    switch (selBox.ID) 
                    { 
                        case "EditorMailBody"
                            _currentEmail.Body = selBox.Text; 
                            break
                    } 
                } 
                _currentEmail.UpdateEmail(); 

    Now the following happens:
    When I change a Text in RadTextbox and leave it the event is fired and anyText_Changed is run (like expected)

    But when I change the text in the RadEditor nothing happens.
    When after editing some Text in the RadEditor I change the Text of a radTextbox and then reactivate the radEditor (by clicking into it) the event from the Textbox AND from the radEditor is fired (jumping into the else if - part)

    So it looks like the OnTextChanged-Event from radEditor does not initiate a Postback.

    Any clue?
  2. Rumen
    Admin
    Rumen avatar
    12849 posts

    Posted 09 Feb 2009 Link to this post

    Hello Ole,

    The RadEditor control is registered as a IPostBackDataHandler from its base class (RadWebControl).
    The problem could appear if you are making a postback using the Javascript form.submit() method instead of the .NET framework's __doPostBack(). RadEditor for ASP.NET AJAX version only uses the MS AJAX compatible methods for refreshing the page. That is why the new editor does not save its content when you submit the form and the TextChanged event is not fired on the server, because the new content is not sent at all. If you are making the postback using form.submit() then to fix this problem you need to manually save the editor content before you call form.submit(). For example, put the following script block on the aspx file before the editor declaration:

    <script type="text/javascript">
            document.forms[0].onsubmit = function()
            {
            $find("<%= EditorMailBody.ClientID %>").saveContent();
            }
    </script>

    Best regards,
    Rumen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. LeBear
    LeBear avatar
    233 posts
    Member since:
    May 2006

    Posted 23 Oct 2009 Link to this post

    Thanks Ole,

    I was doing something similar.  I noticed that the content of the editor was not persisting on a javascript form.submit().  I changed the script to do a __doPostBack(), and it works great.

    I suggest that if you have a JavaScript form.submit(), you should probably always change it to a __doPostBack() since you are working in the .Net environment.  I'm sure there might be other "gotchas" besides this one.

    Thanks for the info!
Back to Top