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

OnTextChanged on radEditor

2 Answers 363 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ole Albers
Top achievements
Rank 2
Ole Albers asked on 04 Feb 2009, 01:12 PM
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 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 09 Feb 2009, 09:17 AM
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.
0
LeBear
Top achievements
Rank 1
answered on 23 Oct 2009, 03:01 PM
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!
Tags
Editor
Asked by
Ole Albers
Top achievements
Rank 2
Answers by
Rumen
Telerik team
LeBear
Top achievements
Rank 1
Share this question
or