MaxLength not working when RadTextBox created in code-behind

10 posts, 0 answers
  1. Adam
    Adam avatar
    14 posts
    Member since:
    Sep 2008

    Posted 24 Mar 2009 Link to this post

    I'm finding that if I add a RadTextBox from the code-behind, the MaxLength property doesn't seem to work correctly. It does work if only the MaxLength property is set from the back page, but if the whole control is created there and added to an asp:Panel, for example, it seems to ignore the MaxLength setting.

    Am I not setting a required property?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Mar 2009 Link to this post

    Hello Adam,

    I tried the scenario and found that its working fine in my end. Checkout the code which I tried.

    ASPX:
    <asp:Panel ID="Panel1" runat="server">  
    </asp:Panel> 

    CS:
    protected void Page_Load(object sender, EventArgs e)  
    {  
        RadTextBox TextBox1 = new RadTextBox();  
        TextBox1.ID = "Id1";      
        TextBox1.MaxLength = 5;  
        Panel1.Controls.Add(TextBox1);  
    Could you paste the code that you tried if it is different from mine?

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    14 posts
    Member since:
    Sep 2008

    Posted 25 Mar 2009 Link to this post

    Sorry, I should've been more clear. Set the TextMode property to MultiLine and you'll see what I mean.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Mar 2009 Link to this post

    Hello Adam,

    I am not clear with what you require exactly. If you set the maxlength property of the RadTexbox to true, the text would be limited to 5 characters, no matter whether you set the TextMode to multiline or singleline.
    c#:
    protected void Page_Load(object sender, EventArgs e) 
        { 
            RadTextBox TextBox1 = new RadTextBox(); 
            TextBox1.ID = "Id1"
            TextBox1.MaxLength = 5; 
            TextBox1.TextMode = InputMode.MultiLine; 
            Panel1.Controls.Add(TextBox1); 
        } 

    Whereas, when the TextMode is set to MultiLine, if you want to limit the text characters entered per line in the textbox, then you would have to set the Columns property as shown below:
    c#:
    protected void Page_Load(object sender, EventArgs e) 
        { 
            RadTextBox TextBox1 = new RadTextBox(); 
            TextBox1.ID = "Id1";         
            TextBox1.TextMode = InputMode.MultiLine; 
            TextBox1.Columns = 5;       
            Panel1.Controls.Add(TextBox1);   
     
        } 

    Thanks
    Princy.
  6. Adam
    Adam avatar
    14 posts
    Member since:
    Sep 2008

    Posted 26 Mar 2009 Link to this post

    What I would like is a multi-line text area created in the code-behind that does not allow the user to type more than a certain number of characters (we can ignore the Columns property for now). In the top example of the last code snippet you sent me, it still allows me to type more than 5 characters. If you created that same Text Box on the front page, it would correctly stop the user from typing any more than 5 characters. What I have found is that a javascript event property gets attached to the control (for the MaxLength property) when it's created from the front page, but not from the code-behind.

     

    Try running your top code snippet. Is it preventing you from entering more than 5 characters?

  7. Adam
    Adam avatar
    14 posts
    Member since:
    Sep 2008

    Posted 23 Apr 2009 Link to this post

    Do you guys have any updates on this?
  8. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 23 Apr 2009 Link to this post

    Hi Adam,

    I gave this a try - and it works like a charm.
    Of course "new lines" are one character so I (for an example) limited to
    as
    df
    as my input.
    To make clear what I made - here may complete aspx:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="TestPMethods.WebForm4" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!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">  
        <telerik:RadScriptManager runat="server">  
        </telerik:RadScriptManager> 
        <div> 
        <asp:Panel ID="Panel1" runat="server">     
        </asp:Panel>    
        </div> 
        </form> 
    </body> 
    </html> 
     
    an my complete code behind:
    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using Telerik.Web.UI;  
     
    namespace TestPMethods {  
        public partial class WebForm4 : System.Web.UI.Page {  
            protected void Page_Load(object sender, EventArgs e) {  
                RadTextBox TextBox1 = new RadTextBox();  
                TextBox1.ID = "Id1";  
                TextBox1.MaxLength = 5;  
                TextBox1.TextMode = InputMode.MultiLine;  
                Panel1.Controls.Add(TextBox1);    
     
            }  
        }  
    }  
     
    That's all - no "hidden things" or something else.
    Could you please tell us which version of Rad controls you use?

    The mine is 2009.1.402.35

    Regards

    Manfred
  9. Adam
    Adam avatar
    14 posts
    Member since:
    Sep 2008

    Posted 23 Apr 2009 Link to this post

    Your code didn't work for me. I'm using version 2008.2.826.20, but I'll try updating tomorrow when I have some time to play around with it.

    Thanks,
    Adam
  10. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 24 Apr 2009 Link to this post

    Hello Adam,

    Manfred is right to ask about your version. We fixed this problem in RadControls for ASP.NET AJAX Q3 2008 SP2 (version 2008.3.1314) .

    RadControls for ASP.NET AJAX Release Notes

    Let us know if you need more information.

    Best regards,
    Daniel
    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.
  11. Adam
    Adam avatar
    14 posts
    Member since:
    Sep 2008

    Posted 24 Apr 2009 Link to this post

    Thanks. That resolved it.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017