13 Answers, 1 is accepted
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.
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.
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.
I found another feature. MaxLength not working, when I carrying text to RadTextBox using mouse in IE6.
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.
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.
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 .)
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"
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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
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%" > </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>
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