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

[Solved] Trouble using client-side Javascript with the old, non-AJAXified version of the RadEditor

6 Answers 171 Views
Editor
This is a migrated thread and some comments may be shown as answers.
v.
Top achievements
Rank 1
v. asked on 28 Apr 2009, 07:44 PM
We are still using the old, ASP.NET, non-AJAXified verison of the RadEditor (due to issues we have with getting the newer version to appear correctly on our website's pages).  There are a couple of things I'd like to do that seem from the forums only to be do-able via the Telerik control's javascript libraries, but I'm having trouble figuring out how to use those in the old version of the tool (where the libraries were not consolidated and accessible via the $ symbol as they are post-Prometheus release).  Here's what I'm looking to do:

1) Check the length of strings being entered into the control, and limit the length to a set number of characters (including the HTML markup) (or, even more ideally, but maybe harder - not limit the allowed length, but detect it and show a warning if a set length is exceeded - but not with a popup but rather by just updating text of a control on the page to show the warning / not show the warning on paste and keystroke).  I see the post at   http://www.telerik.com/community/forums/aspnet-ajax/editor/maximum-text-length.aspx , but it depends on the $ javascript library

2) Capture the paste event and pop up a window offering to strip ALL formatting from the pasted content (not just MS Word formatting), and based on the user's choice either leave the pasted content intact or strip all.  I see the posts on this that point to 

Telerik.Web.DomElement.addExternalHandler as the javascript library to call (pre the introduction of the $ library), but when I try to call this, I get a popup saying "Exception while executing client event "OnClientLoad" Error: 'Telerik' is undefined."  so basically I'm not referencing the library right, but I'm not sure how to do so correctly. 

Many thanks for your aid!

FYI, Here's the code for my test application page that throws the exception cited above:
 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikTest2._Default" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.WebControls" Assembly="RadEditor.Net2" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
      
    <script type="text/javascript">  
    function OnClientLoad(editor, args)  
    {  
        var element = document.all;  
        Telerik.Web.DomElement.addExternalHandler(element, "paste", function(e) {  
            window.setTimeout(function() {  
                //write here your code which you want to execute when the paste event is fired  
                //after that execute the editor's clean filters  
                var oSelElem = editor.get_html();  
                alert(oSelElem);  
                editor.fire("SelectAll");  
                editor.fire("FormatStripper", { value: "FONT" });  
                editor.fire("FormatStripper", { value: "SPAN" });  
                editor.fire("FormatStripper", { value: "CSS" });  
                alert(editor.get_html());  
                alert(oSelElem);  
            }, 300);  
        });  
    }  
    </script> 
 
    <telerik:radeditor runat="server" ID="RadEditor1" OnClientLoad="OnClientLoad"  StripFormattingOptions="NonesupressCleanMessage">  
    </telerik:radeditor> 
    </div> 
    </form> 
</body> 
</html> 
 

6 Answers, 1 is accepted

Sort by
0
v.
Top achievements
Rank 1
answered on 30 Apr 2009, 08:30 PM
Any thoughts?
0
Rumen
Telerik team
answered on 01 May 2009, 03:23 PM
Hi Visar,

I think that the solution provided in this forum thread could be helpful for your scenario:
Character Counter on HTML Source side of Editor.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
v.
Top achievements
Rank 1
answered on 01 May 2009, 09:49 PM
Thanks for your reply. 

I've just tried out the code that's there, but it looks like the attachEventHandler method is not available in my version of the editor and/or the Telerik javascript libraries still aren't getting detected as needed (?) - I still get an error:

In Firefox: Exception while executing client event OnClientLoad Error: editor.attachEventHandler is not a function
In IE:  Exception while executing client event OnClientLoad Error: Object doesn't support this property or method

I also tried to go to the "Validator support example" hyperlink at the site you pointed to, but the link seemed to be broken...  Any other thoughts that might help?

Thanks!
0
Rumen
Telerik team
answered on 05 May 2009, 08:01 AM
Hi Visar,

The provided solution works only for the versions of RadEditor for ASP.NET AJAX (Telerik.Web.UI.dll) released after Q1 2009 (included).

The code is not compatible with the old RadEditor Classic (RadEditor.<Net2>.dll) and if you use it in your project it is better to migrate to the new and much enhanced RadEditor for ASP.NET AJAX. If you prefer the old editor then you can use this solution: Including a Symbol Counter and Limit the Text Length.

In addition, here is the requested link for the Validator example: http://demos.telerik.com/aspnet-ajax/editor/examples/validators/defaultcs.aspx

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
v.
Top achievements
Rank 1
answered on 09 Nov 2009, 09:27 PM


This is occurring with the 2009.2.701.35 version of the ajax controls. It is still not recognizing the AttachEventHandler method of the editor!

Thanks,
Visar
0
Rumen
Telerik team
answered on 12 Nov 2009, 11:45 AM
Hi Visar,

You can see how to attach event handler to RadEditor for ASP.NET AJAX in this help article: attachEventHandler.

Please, also note that we added new MaxTextLenght and MaxHTMLLength properties to limit content size in the latest Q3 2009 version 2009.3.1103 of RadEditor for ASP.NET AJAX. So you should not use custom code in the latest editor to limit the content.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Editor
Asked by
v.
Top achievements
Rank 1
Answers by
v.
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or