control textbox input

  • Thread starter Thread starter Dries De Rudder
  • Start date Start date
D

Dries De Rudder

hey,

what is the best practice to control the user input of a textbox.

e.g. i want a textbox thant can only contain integers, how do i program
this?

thx
 
If you are using the ASP.NET Mobile Controls TextBox just set the Numeric
property to true.

If you are using Windows Forms TextBox you can either handle the KeyDown
event and "eat" the event by settin the Handled property of the KeyEventArgs
of the event to true, hece stopping ti from being processed. You could also
validate the data after it has been entered by subscribing to the Validating
event. Another option is to handle the TextChanged event and if the user
enters an invalid character you could popup a messagebox or tooltip telling
them they have entered invalid data and then you just reset the Text field to
only contain valid data. As you can see, there are a few options for
System.Windows.Forms.TextBox.

If you are using ASP.NET you are kinda stuck with validating the input after
it's been put there... You could use a RegularExpressionValidator for this.
 
Why don't you respond to the validation event and validate the data in
the text box?

-----Original Message-----
From: Dries De Rudder [mailto:[email protected]]
Posted At: Wednesday, August 10, 2005 6:12 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: control textbox input
Subject: control textbox input


hey,

what is the best practice to control the user input of a textbox.

e.g. i want a textbox thant can only contain integers, how do i program
this?

thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top