![]() |
|
#1
|
|||
|
|||
C#: i need the Textbox to allow integer onlyguys,
I'm building an ASP .net webpage using Microsoft Visual C#. I have a textbox, a label and a command button. I need to make an error checking code so that the textbox only allow integers to be entered into it. But it should be checked when the command button is clicked which then the error should be displayed using the label.. Is there any specific commands/keywords i need to use? |
|||
|
#2
|
|||
|
|||
Re: C#: i need the Textbox to allow integer onlyI don't know of any in built mechanism for it but you may try by casting the text in the text box to an int. And then catch the exception if and when it occurs. Putting the code in the event handler for the button would solve the purpose.
Netnut. |
|
#3
|
|||
|
|||
Re: C#: i need the Textbox to allow integer onlyAaron you should look at using a RegularExpressionValidator. The validator is placed on the ASPX page, you indicate which control you are validating with the ControlToValidate property
Something like this: Code:
On your button you would set the CausesValidation property to true. Code:
I wouldn't suggest handling exceptions for this. Exceptions are expensive, only use exception handling where it is necessary. |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Integer overflow check? | s.hanson | C++ Forum | 2 | 24-Sep-2007 22:48 |
| Textbox in Form | xtinct | MS Visual C++ / MFC Forum | 5 | 03-Jan-2007 04:17 |
| Fortran problem... | Justin Fox | Miscellaneous Programming Forum | 6 | 24-Oct-2006 15:30 |
| Operator Overloading | the_crazyman | C++ Forum | 4 | 02-Jun-2005 07:43 |
| Help with integer inputs | jrl134 | C++ Forum | 1 | 20-Feb-2005 00:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The