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

RadTextBox multiline, MaxLength and Enter

13 Answers 708 Views
Input
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 16 Jan 2009, 11:08 AM
RadTextBox count Enter as one char, but really, Enter is two chars, so I get exception when inserting to database. Is it possible to count Enter as two chars?

13 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 16 Jan 2009, 11:41 AM
Hello Andrey,

Actually the number of characters depends on the browser. [Enter] is two characters only in Internet Explorer. RadInput textboxes regard [Enter] as one character, because this is related to the MaxLength property.

Here is a forum thread, which demonstrates how you can count the number of Enters in a textbox:

http://www.telerik.com/community/forums/aspnet-ajax/input/counting-characters.aspx


Kind regards,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andrey
Top achievements
Rank 1
answered on 16 Jan 2009, 01:06 PM
Ok, I have ff 3.0.5,  RadTextBox(2008.3.1314.35) with Maxlength 5. I have typed a[enter]b[enter]c. Then I try to insert this to database in field nvarchar(5). I get exception, because length of Text property is seven. I think if I set MaxLength to five, length of Text property cannot be more then five. MaxLength property working incorrect now, I think it's bug. Must be: radTextBox.Text.Length <= radTextBox.MaxLength.






0
Dimo
Telerik team
answered on 16 Jan 2009, 03:16 PM
Hi Andrey,

A change in this behavior will be breaking for all current applications, so we will consider implementing it if there is a popular demand for it. In the meantime, please check the length of the input string on the server as well (which is a good practice anyway), or use nvarchar(10).

Kind regards,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andrey
Top achievements
Rank 1
answered on 16 Jan 2009, 08:17 PM
Yes, of course, but you can add property, for example, MaxLengthType, to save backward compability. I think, you need to change current implementation, because it is very strange. I set MaxLength, but length of input string can be more then MaxLength...
0
Dimo
Telerik team
answered on 19 Jan 2009, 11:12 AM
Hello Andrey,

Thanks for your feedback. We will consider implementing this feature for a next version of the control.

Greetings,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andrey
Top achievements
Rank 1
answered on 19 Jan 2009, 12:01 PM
Thanks.

I found another feature. MaxLength not working, when I carrying text to RadTextBox using mouse in IE6.
0
Dimo
Telerik team
answered on 19 Jan 2009, 12:26 PM
Hello Andrey,

Yes, this was reported earlier today. We have fixed this problem and a new build will be available for download from the Nightly Builds page tomorrow:

http://www.telerik.com/account/latest-internal-builds.aspx

Sincerely yours,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
JANET BROWNE
Top achievements
Rank 1
answered on 11 Mar 2009, 02:02 PM
If you paste text from the clipboard into the RadTextBox it appears to bypass the MaxLength check too, allowing more than MaxLength chars to be entered into the RadTextBox.  I found this with version 2008.2.1001.35, has this been fixed too?
0
Sebastian
Telerik team
answered on 11 Mar 2009, 02:14 PM
Hello Janet,

Have you tested your code with the latest build from your account? You may also switch to the official Q1 2009 release of the product (2009.1.311) which will be announced later today in public.

Regards,
Sebastian
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
Sri
Top achievements
Rank 1
answered on 07 Jul 2010, 09:46 PM
Hi,

I wanted to find out if there is a property for Multiline Radtextbox  which can prompt me the number of characters left while I am entering text in to the textbox.( I am setting the maxlength to 2000 characters. The Multiline text box should not take more than 2000 characters however the user should know the count .) 
0
Dimo
Telerik team
answered on 08 Jul 2010, 08:36 AM
Hello Sri,

The described behavior is not available out-of-the-box, but you can achieve it like this:

<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadTextBox ID="RadTextBox1" runat="server" MaxLength="20" TextMode="MultiLine" onkeydown="countChars()">
    <ClientEvents OnLoad="saveInstance" />
</telerik:RadTextBox>
 
<script type="text/javascript">
 
var rtbInstance;
 
function saveInstance(sender, args)
{
    rtbInstance = sender;
}
 
function countChars()
{
    window.setTimeout(function(){
        $get("charsCount").innerHTML = rtbInstance._escapeNewLineChars(rtbInstance.get_textBoxValue(), "%0A").length;
    },1);
}
 
</script>
 
<br /><br />
 
<span id="charsCount"></span>
 
</form>
</body>
</html>


All the best,
Dimo
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
0
Sri
Top achievements
Rank 1
answered on 08 Jul 2010, 10:13 PM

I got an error saying session state not found. I tried both your code and the my modified code. It did not work. Can you look at the following code and see what could be wrong. FYI the text box is present in a Web Control Form and it shows up only after user has logged in to the site. And I also want to know how to display the count to the UI.

<

 

style type="text/css">

 

 

.style1

 

{

 

width: 26px;

 

}

</

 

style>

 

<

 

div class="formLayout" >

 

<

 

fieldset>

 

 

<legend>Notes</legend>

 

 

<table width="100%">

 

 

<tr><td width="30%" valign="top">

 

 

 

<table >

 

 

 

<tr>

 

 

<td colspan="2"><asp:ValidationSummary ID="valSummary" runat="server" DisplayMode="List" CssClass="validationSummary" ValidationGroup="Note" /></td>

 

 

</tr>

 

 

<tr>

 

 

<td width="10%" class="labelTop">Action:</td>

 

 

<td width="300" align="left">

 

 

<telerik:RadComboBox runat=server ID="ddlAction" Width="100%" Skin="Windows7" />

 

 

<asp:CustomValidator runat="server" ID="custReqActionSelection" ErrorMessage="Action is required." OnServerValidate="custReqActionSelection_Validate" ControlToValidate="ddlAction" Display="None" ValidationGroup="Note" />

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td width="10%" class="labelTop">Result:</td>

 

 

<td width="300" align="left">

 

 

<telerik:RadTextBox runat="server" ID="txtResult" TextMode="MultiLine" Rows="4" Width="99%"

 

 

MaxLength="2000" onkeydown="countChars()"> >

 

 

<ClientEventsOnLoad="saveInstance"/> </telerik:RadTextBox>

 

 

 

<script type="text/javascript">

 

 

var

 

rtbInstance;

 

 

 

 

 

function

 

saveInstance(sender, args)

 

{

rtbInstance = sender;

}

function

 

countChars() {

 

var

 

charsCount= rtbInstance.get_textBoxValue().length;

 

// window.setTimeout(function() {

//

// $get("charsCount").innerHTML = rtbInstance._escapeNewLineChars(rtbInstance.get_textBoxValue(), "%0A").length;

// },1);

}

 

</

 

script>

 

 

<

 

br/><br/>

 

 

 

<asp:CustomValidator runat="server" ID="custReqResultText"

 

 

ErrorMessage="Result is required and cannot exceed 2000 characters."

 

 

OnServerValidate="custReqResultText_Validate" ControlToValidate="txtResult"

 

 

Display="None" ValidationGroup="Note" ValidateEmptyText="true" />

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td width="10%" >&nbsp;</td>

 

 

<td width="300" align="right">

 

 

 

<asp:Button runat="server" ID="btnSaveNote" Text="Save" OnClick="btnSaveNote_Click"

 

 

ValidationGroup="Note" CausesValidation="False" />

 

 

</td>

 

 

</tr>

 

 

 

</table>

 

 

 

</td>

 

 

 

 

<td align="left" width="70%" valign="top">

 

 

 

<table >

 

 

 

<tr>

 

 

<td colspan="2"></td>

 

 

</tr>

 

 

<tr><td width="10%" class="labelTop">History:</td>

 

 

<td width="100%" align="left">

 

 

 

<telerik:RadGrid ID="noteList" runat="server" AutoGenerateColumns="False" DataKeyNames="NoteId"

 

 

CssClass="Grid" Width="100%" AllowFilteringByColumn="False" AllowSorting="True"

 

 

GridLines="Vertical" ActiveItemStyle-Wrap="true" AllowPaging="true" >

 

 

<MasterTableView>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

<ItemStyle Width="20px" Wrap="true" HorizontalAlign="Center"/>

 

 

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

 

 

 

<telerik:GridBoundColumn HeaderText="Action" DataField="ActionDesc" SortExpression="ActionDesc" ItemStyle-Wrap="true" />

 

 

<telerik:GridBoundColumn HeaderText="Result" DataField="Text" ItemStyle-Wrap="true"/>

 

 

<telerik:GridBoundColumn HeaderText="Created By" DataField="CreatedBy" SortExpression="CreatedBy" ItemStyle-Wrap="true" MaxLength="20"/>

 

 

<telerik:GridBoundColumn HeaderText="Created On" DataField="CreatedOn" SortExpression="CreatedOn" ItemStyle-Wrap="true"/>

 

 

 

 

</Columns>

 

 

 

 

</MasterTableView>

 

 

<HeaderStyle CssClass="GridHeader" />

 

 

<GroupingSettings CaseSensitive="False" />

 

 

 

 

</telerik:RadGrid>

 

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

 

 

</td>

 

 

 

</tr>

 

 

 

</table>

 

 

 

</fieldset>

 

 

</

 

div>

 

0
Dimo
Telerik team
answered on 09 Jul 2010, 12:17 PM
Hello Sri,

Currently you are missing an HTML element with a client ID of "charsCount" - this is the element, which will show the remaining characters. Please inspect my demo once again more carefully.

In addition, if the RadTextBox and Javascript code are added to the page after an AJAX request, you need to include the <script> tag inside a RadScriptBlock control.

http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html


Greetings,
Dimo
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
Tags
Input
Asked by
Andrey
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Andrey
Top achievements
Rank 1
JANET BROWNE
Top achievements
Rank 1
Sebastian
Telerik team
Sri
Top achievements
Rank 1
Share this question
or