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?
Am I not setting a required property?
9 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 25 Mar 2009, 07:54 AM
Hello Adam,
I tried the scenario and found that its working fine in my end. Checkout the code which I tried.
ASPX:
CS:
Could you paste the code that you tried if it is different from mine?
Thanks,
Princy.
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); |
} |
Thanks,
Princy.
0
Adam
Top achievements
Rank 1
answered on 25 Mar 2009, 03:19 PM
Sorry, I should've been more clear. Set the TextMode property to MultiLine and you'll see what I mean.
0
Princy
Top achievements
Rank 2
answered on 26 Mar 2009, 06:56 AM
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#:
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#:
Thanks
Princy.
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.
0
Adam
Top achievements
Rank 1
answered on 26 Mar 2009, 02:12 PM
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?
0
Adam
Top achievements
Rank 1
answered on 23 Apr 2009, 03:43 PM
Do you guys have any updates on this?
0
ManniAT
Top achievements
Rank 2
answered on 23 Apr 2009, 11:24 PM
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:
an my complete code behind:
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
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> |
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); |
} |
} |
} |
Could you please tell us which version of Rad controls you use?
The mine is 2009.1.402.35
Regards
Manfred
0
Adam
Top achievements
Rank 1
answered on 24 Apr 2009, 12:14 AM
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
Thanks,
Adam
0
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.
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.
0
Adam
Top achievements
Rank 1
answered on 24 Apr 2009, 06:44 PM
Thanks. That resolved it.