How to count character of TextBox in ASP.NET

Posted by Rahmankhan under ASP.NET on 6/10/2013 | Points: 10 | Views : 6546 | Status : [Member] | Replies : 5
How to count character of TextBox in ASP.NET


ex : i want enter 140 character in one textbox while i start my work character want reduce




Responses

Posted by: Raj.Trivedi on: 6/10/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello

You can achieve this by using Jquery

http://www.yourinspirationweb.com/en/jquery-tips-tricks-how-to-limit-characters-inside-a-textarea/

Download the plugin from here.

Here is the demo

http://www.yourinspirationweb.com/example/maurizio/textarea/textarea_plugin2.html

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Rahmankhan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja_89 on: 6/11/2013 [Member] Starter | Points: 25

Up
0
Down
Hai Techie


You can achieve this length property of a text box

Code:

int a = nametxtbx.Text.Length; // Textbox to be count
filepathtxt.Text = Convert.ToString(a).ToString(); //Result shown to another textbox



Regards


Rahmankhan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rahmankhan on: 6/11/2013 [Member] Starter | Points: 25

Up
0
Down
thnks
RajTrivedi

Rahmankhan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/11/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Limit_number_of_characters_TextBox._Default" %>


<!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>Untitled Page</title>
<script type="text/javascript">
function validateLimit(obj, divID, maxchar) {
objDiv = get_object(divID);
if (this.id) obj = this;
var remaningChar = maxchar - obj.value.length;
if (objDiv){
objDiv.innerHTML = remaningChar + " characters left";
}
if (remaningChar <= 0) {
obj.value = obj.value.substring(maxchar, 0);
if(objDiv) {
objDiv.innerHTML = "0 characters left";
}
return false;
}
else
{ return true; }
}
function get_object(id) {
var object= null;
if (document.layers) {
object = document.layers[id];
} else if (document.all) {
object = document.all[id];
} else if (document.getElementById) {
object = document.getElementById(id);
}
return object;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="lblMsg1">140 characters left</div>
<asp:TextBox ID="TextBox1" runat="server" Height="50px" MaxLength="140"
TextMode="MultiLine" Width="600px" ToolTip="Summary:(140 characters)"
onkeyup="return validateLimit(this, 'lblMsg1', 140)"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" Display="Dynamic"
SetFocusOnError="True">*</asp:RequiredFieldValidator>
<br /><br /><br />

<br />
</div>
</form>
</body>
</html>


If this post helps you mark it as answer
Thanks

Rahmankhan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 6/11/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try with this,

http://www.c-sharpcorner.com/blogs/7247/how-to-count-character-of-textbox-in-asp-net.aspx

Thanks,
Bagesh Kumar Singh


Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Rahmankhan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response