473,411 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Setting a limit for the textbox . . .

CodeNoobster
Hey everyone, little problem here, I have managed to make text dynamically appear in a text-box while I enter text into another.

how ever I would like to know to to limit the amount of text that is dynamically entered(I'd say about 10 characters at most). Any suggestions and help would be greatly appreciated!

here's a sample of what I have done so far:

Expand|Select|Wrap|Line Numbers
  1. Random r = new Random();
  2. int IDrandom = r.Next(0, 9);
  3. Emp_ID.Text += IDrandom.ToString();
  4.  
  5. //Emp_ID.MaxLength = 10; does not work
  6.  
Jul 18 '14 #1

✓ answered by horace1

in the specification of TextBox
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

it states
In code, you can set the value of the Text property to a value that has a length greater than the value specified by the MaxLength property. This property only affects text entered into the control at run time.

hence the MaxLength property does not work as you expect

after you have added the latest character to Emp_ID.Text could you read the Emp_ID.Text property as a String and use the String.Remove() method to delete all but the last 10 characters then write it back into Emp_ID.Text

3 1741
horace1
1,510 Expert 1GB
in the specification of TextBox
http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

it states
In code, you can set the value of the Text property to a value that has a length greater than the value specified by the MaxLength property. This property only affects text entered into the control at run time.

hence the MaxLength property does not work as you expect

after you have added the latest character to Emp_ID.Text could you read the Emp_ID.Text property as a String and use the String.Remove() method to delete all but the last 10 characters then write it back into Emp_ID.Text
Jul 19 '14 #2
Thanks horace1 that helps. thumbs up
Jul 19 '14 #3
horace1
1,510 Expert 1GB
in fact as you are only adding one character at a time you only need to delete the first character, e.g.
Expand|Select|Wrap|Line Numbers
  1. Emp_ID.Text += IDrandom.ToString();
  2. string s = Emp_ID.Text;
  3. if (s.Length > 10) s=s.Remove(0, 1);
  4. Emp_ID.Text=s;
Jul 20 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: WhiskyRomeo | last post by:
I have a bound textbox (bindings are set at design time) to a dataset column. Sometimes the value of this textbox must be set so that the underlying database field gets updated to null when using...
4
by: Paul E Collins | last post by:
I'm writing an application with a TextBox control on its main form. I'm running the application under WinXP Pro, so (as I understand it) there should be no practical limit to the number of...
4
by: David Kyle | last post by:
Hello there, I'm having some problems setting the TextBox.Text Property in my code and having it returned to the client in the source when the TextBox.TextMode="Password". I know this is...
5
by: ScareCrow | last post by:
How do I go about limiting a textbox to accepting numeric key input from the keyboard in vb.net? --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading...
6
by: Avi G | last post by:
Hi, what is the code to limit a textbox that will accept only text and not number private void button1_Click(object sender, EventArgs e) { if (textBox1.Text = "numbers") { // do something }
2
by: Sridhar | last post by:
Hi, I have a user control which has a textbox control and a button. I have created a property to get and set the text box value. In the Page_Load method of the Page that contains the user...
0
by: swep | last post by:
I have a Gridview control that has 5 columns. When a user selects "Edit", I'd like to make 3 of the columns set to "Readonly". However, when I set the 3 column's boundfield properties to...
1
by: sanjrose | last post by:
Hi, I hav got three fields in a UI where the first field is a listbox with values fetched from the database and the second,third fields are textboxes which should get their corresponding value...
1
by: =?Utf-8?B?d2NsYXJrZTEwMQ==?= | last post by:
Hello all, I've created the following ASP.NET code sample which, when rendered, displays a 100% textbox within a single cell table. The problem is that Internet Explorer (6 or 7) truncates the...
10
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.