Click here to Skip to main content
15,888,610 members
Articles / Web Development / ASP.NET
Article

NumericInput

Rate me:
Please Sign up or sign in to vote.
2.78/5 (5 votes)
8 Mar 2006CPOL2 min read 82.3K   503   36   24
A numeric input control.

Introduction

This code drop is part of a smash and grab series. If you're in a rush, you can just grab this code and insert it into your application, no understanding is required. When you have some time, you can review the source code.

Background

I was presented with a project to convert an Access single-user application into a web-based multi-user SQL Server application. The Access application had a number of numeric input boxes. I couldn't find what I needed anywhere on the net. So, I had to find a solution myself.

Using the code

  • Download the project, unzip it to somewhere on your hard disk.
  • Create a new ASP.NET project.
  • Select Tools > Choose toolbox items.
  • Navigate to the unzip folder and select the DLL.
  • The new server control now appears in the toolbox under General.
  • Drag an instance of it onto Default.aspx.

Now, set these properties on the NumericInput:

  • NumericFormat: Integer, Float or Currency.
  • DecimalSeparator: If left blank, the current culture's default is used (usually '.' or ','). To override, enter '.' , ',' or any other character (don't include the quotes).

Points of interest

The control also works with data binding for use in GridView, etc. The control extracts the JavaScript from the DLL using WebResource. Search CodeProject for the keywords webresource redux for details on this subject.

SmashGrab / Redux series

I have recently started two series of articles here at CodeProject. Smash and Grab is intended as a series of short articles on one specific code technique. Redux is intended as a series of longer articles which attempts to reduce a complicated topic (like GridView) into its basic constituent parts and shows that once you have all the information, it isn't really that hard. To find the Smash and Grab articles, search for the keyword SmashGrab. To find the Redux articles, search for the keyword Redux.

I welcome any contributions to either series, but please follow the guidelines when submitting articles to either.

Conclusion

There you go, a free ASP.NET 2.0 numeric input control that suits my needs and hopefully yours.

Updates

  • 2006/02/21
    • Internationalized so that the decimal separator (usually '.' or ',') is determined by the current culture.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generala small bug Pin
tuhucon6-May-07 5:53
tuhucon6-May-07 5:53 
GeneralNumericInput Javascript Pin
Brad Vin23-Mar-06 0:58
Brad Vin23-Mar-06 0:58 
GeneralRe: NumericInput Javascript Pin
Gary Dryden23-Mar-06 2:14
Gary Dryden23-Mar-06 2:14 
GeneralAllowing to type directly ".5" Pin
Antoine Marie9-Mar-06 3:22
Antoine Marie9-Mar-06 3:22 
GeneralNeed the DLL Pin
Antonino Ferrando7-Mar-06 23:47
Antonino Ferrando7-Mar-06 23:47 
GeneralRe: Need the DLL Pin
RatulSaikia8-Mar-06 19:46
RatulSaikia8-Mar-06 19:46 
Question.DLL File Not Included Pin
Big Tones7-Mar-06 12:53
Big Tones7-Mar-06 12:53 
AnswerRe: .DLL File Not Included Pin
Gary Dryden7-Mar-06 13:03
Gary Dryden7-Mar-06 13:03 
GeneralRe: .DLL File Not Included Pin
Big Tones7-Mar-06 15:17
Big Tones7-Mar-06 15:17 
GeneralRe: .DLL File Not Included Pin
Antonino Ferrando7-Mar-06 23:48
Antonino Ferrando7-Mar-06 23:48 
AnswerRe: .DLL File Not Included Pin
hitman_s23-Jun-06 20:18
hitman_s23-Jun-06 20:18 
GeneralAuxilio Pin
GerardoPeder22-Feb-06 3:27
GerardoPeder22-Feb-06 3:27 
GeneralRe: Auxilio Pin
Gary Dryden22-Feb-06 4:22
Gary Dryden22-Feb-06 4:22 
GeneralRe: Auxilio Pin
GerardoPeder23-Feb-06 4:06
GerardoPeder23-Feb-06 4:06 
GeneralRe: Auxilio Pin
Gary Dryden23-Feb-06 4:47
Gary Dryden23-Feb-06 4:47 
GeneralRe: Auxilio Pin
Paul Conrad27-Feb-06 15:49
professionalPaul Conrad27-Feb-06 15:49 
GeneralRe: Auxilio Pin
Paul Conrad27-Feb-06 15:50
professionalPaul Conrad27-Feb-06 15:50 
GeneralHardcoded decimal separetor = No international support Pin
simone massaro21-Feb-06 7:30
simone massaro21-Feb-06 7:30 
GeneralRe: Hardcoded decimal separetor = No international support Pin
Gary Dryden21-Feb-06 8:59
Gary Dryden21-Feb-06 8:59 
GeneralRe: Hardcoded decimal separetor = No international support Pin
simone massaro21-Feb-06 9:26
simone massaro21-Feb-06 9:26 
GeneralRe: Hardcoded decimal separetor = No international support Pin
dferreira0427-Mar-06 18:43
dferreira0427-Mar-06 18:43 
GeneralRe: Hardcoded decimal separetor = No international support Pin
simone massaro8-Mar-06 3:48
simone massaro8-Mar-06 3:48 
GeneralRe: Hardcoded decimal separetor = No international support Pin
dferreira0428-Mar-06 4:03
dferreira0428-Mar-06 4:03 
GeneralRe: Hardcoded decimal separetor = No international support Pin
simone massaro8-Mar-06 5:15
simone massaro8-Mar-06 5:15 
Hello Dave,
Internazionalization is a really hot topic nowadays. I'm not an expert by all means, but I think it is worth to clarify a bit more for the other readers that are interested in building internation-aware controls:
IIS has a thread pool that is used to serve client requests. Each client request get assigned a thread from the pool. The code above is setting the culture for the particular thread assigned to the current request. It does not change the culture of the server, and it does not change the culture for any other consecutive request from other clients.
By default ASP 2.0 detect the culture of the web browser using the browser cookie and sets the current UI culture for the thread. This means that if your control reads the current thread culture then there is no extra work to be done from the developer: it will work out of the box.
Now there are some cases in which the auto-detection migth not be convenient for the user (e.g. a Spanish-speaking user using a computer in a Chinese Internet Cafe'). In that case you could override the current UI culture based on a used preference. In example your web application migth be detecting the current UI culture by default but it migth also have a drop down somewhere in an option page that allows the user to "switch" the page language on the fly. This actually allows for some very cool stuff if combined with the new resource support in ASP 2.0
When you work on an application for "internal use" it is probably ok to use the hardcoded language, but it only takes two extra lines of code to set the correct culture, and IT depertment can "change their mind" on what language they want to support at any point in time, so you are better off adding those extra lines.
On the other end if you intend to seel your controls then the internationl support opens the door to a huge international market.
On a side note I believe that in USA it is mandatory to provide foreign language support for all user interface in any work plave in which more then X percent of the work force speak english as second language (ESL) (this is very common on the factory floor). I believe that it is also mandatory for all government-related application to support the language used form their local minority. Again this requirement migth not be enforced in all cases, but it is a good selling point when you bid on a project.
Doing it rigth the first time will save you from having to fix the code later: it is always easier to add the internation support from the beginning then forcing it later, and once you start thinking "international" then it will come natural to you.
ASP 2.0 also offer a convenient way to test internation feature by overriding the language of the ASPX page trough the property "Culture" of the Page object which by default is set to "auto".
You can find more information on internationalization in ASP 2.0 at the following link:

http://www.asp.net/QuickStart/aspnet/doc/localization/localization.aspx


-- modified at 11:16 Wednesday 8th March, 2006

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.