473,403 Members | 2,366 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,403 software developers and data experts.

text field that accepts only numbers

Is there any way in .NEt to make textbox which will automaticly accept only numbers?

Or do I have to check on textChange is inserted character number or not?
Aug 21 '06 #1
8 7378

"Alfa & Omega" <al*****@gmail.comwrote in message
news:ec**********@ss408.t-com.hr...
Is there any way in .NEt to make textbox which will automaticly accept
only numbers?

Or do I have to check on textChange is inserted character number or not?

You can use a RegularExpressionValidator to perform a validation check on
the textbox (WebForms). Not sure if the same exists for WinForms :)
HTH,
Mythran
Aug 21 '06 #2
Hi,

What version?
What kind of app?

Depending of the above answers you have to use a different method.
In win app (1.1 , 2.0 ) you can hook KeyDown event and check if it's a
number (or a control key),
In win app 2.0 you have a maskedTextBox control in addition to the "regular"
button

In web you have to use jscript to do it.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alfa & Omega" <al*****@gmail.comwrote in message
news:ec**********@ss408.t-com.hr...
Is there any way in .NEt to make textbox which will automaticly accept
only numbers?

Or do I have to check on textChange is inserted character number or not?


Aug 21 '06 #3
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote in message
news:uE**************@TK2MSFTNGP03.phx.gbl...
| Hi,
|
| What version?
| What kind of app?
|
| Depending of the above answers you have to use a different method.
| In win app (1.1 , 2.0 ) you can hook KeyDown event and check if it's a
| number (or a control key),
| In win app 2.0 you have a maskedTextBox control in addition to the "regular"
| button
|
| In web you have to use jscript to do it.
|
|
It's for win app (1.1)..

Thanks you guys for answers, I'll hook KeyDown event..

Now, another qouestion (it's not about textboxes but I don't won't to open so much threads :) ).

My app uses internet connection..
How can I check is there valid active internet connection?

Aug 21 '06 #4
Hi,
Now, another qouestion (it's not about textboxes but I don't won't to open
so much threads :) ).
You should open a new thread for a new question
My app uses internet connection..
How can I check is there valid active internet connection?
This is a tricky question, depending of what you mean with "internet
connection" is the answer you get.

In general the way is just try to do what you need and if you get an error
of some kind then you do not have the kind of connectivity you need.

If you do this with a background thread your app will keep working as
normal.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 21 '06 #5
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote in message
news:eg**************@TK2MSFTNGP03.phx.gbl...
|
| This is a tricky question, depending of what you mean with "internet
| connection" is the answer you get.
|
| In general the way is just try to do what you need and if you get an error
| of some kind then you do not have the kind of connectivity you need.
|
| If you do this with a background thread your app will keep working as
| normal.
|
|
Hm... I tryed that (I'm using webbrowser control, imported mshtml.dll), but when there is no
internet connection (I'm catching the exception: "Host name cannot be resolved..."), my app waits
for more then one minute before it shows that there is no connection...

Is there any way to make that time shorter??

Can it be done directly with some kind of property for mshtml.dll, maybe timeout control or
something?
Aug 21 '06 #6
Hi,

>
Hm... I tryed that (I'm using webbrowser control, imported mshtml.dll),
but when there is no
internet connection (I'm catching the exception: "Host name cannot be
resolved..."), my app waits
for more then one minute before it shows that there is no connection...

Is there any way to make that time shorter??
Yes, do not use WebBrowser , use a WebRequest for example. The key of the
matter is to do it in the background, in another thread. you cannot run a
WebBrowser in a worker thread.
You have to use a WebRequest.

Beside that I don't know if you can control the timeout of the DNS client.
but at least if you run it in the background your app will continue to
respond.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 21 '06 #7
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.uswrote in message
news:Or**************@TK2MSFTNGP05.phx.gbl...
|
| Yes, do not use WebBrowser , use a WebRequest for example. The key of the
| matter is to do it in the background, in another thread. you cannot run a
| WebBrowser in a worker thread.
| You have to use a WebRequest.
|
| Beside that I don't know if you can control the timeout of the DNS client.
| but at least if you run it in the background your app will continue to
| respond.
|
|
Thanks for the solution..it works great ;-)

Best regards,
Igor
Aug 21 '06 #8
Here's a VB version. Should be trivial to translate:
http://groups.google.com/group/micro...565c4ded?hl=en

/claes

"Alfa & Omega" <al*****@gmail.comwrote in message
news:ec**********@ss408.t-com.hr...
Is there any way in .NEt to make textbox which will automaticly accept
only numbers?

Or do I have to check on textChange is inserted character number or not?


Aug 22 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
13
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
2
by: Todd_M | last post by:
I was wondering what anyone might suggest as "best practice" patterns for streaming out fixed formatted text files with C#? Let's say we get our data in a dataset table and we need to iterate over...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
3
by: Klaus Brune | last post by:
Hello all, When one tabs through a form (specifically, in Firefox), all the text in a field is automatically selected. What I'm looking for is a way to put a function (in onFocus perhaps)...
0
by: Pete D. | last post by:
I haven't played with this but just a thought, I remember reading this is stored as HTML. I remember, http://allenbrowne.com/Access2007.html again this might be a hint. "CES"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.