Reputation:
How can I count characters in a TextBox using ASP.NET(C#)?
Upvotes: 2
Views: 2465
Reputation: 1
For count characters
TextBox.Text.Length;
and if you want validate number goes over 50 that add tag in text.
Maybe this in my perception:
int countWord = Textbox.Text.Length();
if(countWord > 50){
string text = Textbox.Text.ToString()+"SomeTag";
}else{
string text = Textbox.Text.ToString();
}
Upvotes: -1
Reputation: 115548
This is the property to see how long the text is during a postback:
TextBox.Text.Length;
TextBox: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx
Text Property: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.text.aspx
String Length Property: http://msdn.microsoft.com/en-us/library/system.string.length.aspx
String str = TextBox.Text;
if(str.Length > 50)
{
str = str.SubString(0, 50) + "<br/>" + str.SubString(50);
}
Upvotes: 8
Reputation:
How to count charachters in the textbox,and if the nubmers goes over 50 that add
tag in charachters?
Upvotes: 0