Getting Row Count

4 posts, 1 answers
  1. Jeremy Robinson
    Jeremy Robinson avatar
    5 posts
    Member since:
    Mar 2010

    Posted 21 Jun 2010 Link to this post

    Hi All,

    I have a RadEditor on my ASP.NET page.
    I want to get the number of lines users have entered and want to restrict users to enter more than X lines.

    Is there are property of RADEditor using which I can achieve this ?

    Thanks
  2. Answer
    Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 22 Jun 2010 Link to this post

    Hello Jeremy,

    RadEditor does not offer the required feature to limit the lines because the HTML markup is just a string it is not able to determine if the text entered will fit in a certain amount of space. However, you can enhance the provided code below to fit your scenario. Here is a basic example on how to limit the line length in the editor content area:

    <telerik:RadEditor ID="RadEditor1" OnClientLoad="OnClientLoad" runat="server"></telerik:RadEditor>
    <script type="text/javascript">
    function OnClientLoad(editor)
    {
        editor.attachEventHandler("onkeyup", function(e)
        {
            var brs = editor.get_document().body.getElementsByTagName("BR");
            if (brs.length > 2)
            {
                alert("You can only have 3 lines of text! Undoing last operation!");
                editor.undo(1);
            }
        } );
    }
    </script>

    Here is a another base solution which will help you to achieve your scenario:

    <script type="text/javascript"> 
     
    function checkEditor(editor, ev) 
    {    
        var targetHeight = editor.get_document().body.scrollHeight; 
        var allowedHeight = editor.AllowedHeight; 
     
         
        if (targetHeight > allowedHeight) 
        { 
            alert("Maximum allowed size content height is 350 pixels"); 
             
            if (ev) 
            { 
              ev.returnValue = false; 
              ev.cancelBubble = true; 
            } 
             
            return false; 
        } 
        return true; 

     
    function OnClientCommandExecuted(editor,commandName, tool) 

        var allow = checkEditor(editor); 
         
        if (false == allow) 
        { 
            editor.undo(1); 
        } 

     
    function OnClientLoad(editor) 
    {    
       //Set content area to be one inch high 
       var iframe = editor.get_contentAreaElement(); 
       iframe.style.height = "350px"; 
       iframe.style.border = "1px solid red"; 
        
       editor.AllowedHeight = iframe.offsetHeight; 
        
        var resizeFnRef = function (e){checkEditor(editor, e)}; 
      
        editor.attachEventHandler("keydown", resizeFnRef); 
     

    </script> 
    <telerik:RadEditor id="RadEditor1"  
        Height = "350px"
        OnClientLoad="OnClientLoad"
        OnClientCommandExecuted = "OnClientCommandExecuted"
        Runat="server">
    </telerik:RadEditor>



    Sincerely yours,
    Rumen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TheXplorer
    TheXplorer avatar
    6 posts
    Member since:
    Jul 2009

    Posted 28 Apr 2015 in reply to Rumen Link to this post

    Hi Ruman,

    i am able to get alert if the row crossed, however it is not removing the extra row. 

    for copy and paste also it is not working.

    please provide solution 

  5. TheXplorer
    TheXplorer avatar
    6 posts
    Member since:
    Jul 2009

    Posted 03 May 2015 Link to this post

    Any help!

    I am able to get number of rows, however it is not removing the content when it reached max level

Back to Top