Avatar of shpresa
shpresaFlag for United States of America

asked on 

text box validation word count (asp.net)

Hello,

I have a text box assigned as nvarchar(2000) in the database but i really want  it to be to a max 300 words.
I tryed using maxlegth in <asp:Textbox ID="txtN_Hero" runat="server" Width="600px" MaxLength="300"
and this didn't work. Is there any other validation to check for a max wording in this textbox? I can't change the database field because i have data on the database and it might shorten them out once i change it.

Thanks
ASP.NET.NET App Servers

Avatar of undefined
Last Comment
Francisco Igor
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

The MaxLength property is for the number of characters allowed
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.maxlength(v=vs.110).aspx

To limit the number of words, first set the MaxLength to 2000 to ensure compliance with the database and then use validation to ensure the max number of words is not exceeded
https://msdn.microsoft.com/en-us/library/aa479013.aspx
Avatar of Rafiq J
Rafiq J
Flag of India image

int  Length =  textbox.text.length;

if(length <300 )
{
perform your operation....
}
SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo