text field that accepts only numbers

  • Thread starter Thread starter Alfa & Omega
  • Start date Start date
A

Alfa & Omega

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?
 
Alfa & Omega said:
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
 
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 ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message
| 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?
 
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 ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message
|
| 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?
 
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 ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message
|
| 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
 

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

Similar Threads


Back
Top