.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Ajax >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Numeric textbox with Ajax in ASP.NET

Posted By:Pankaj Mishra       Posted Date: August 09, 2008    Points: 10    Category: Ajax    URL: http://www.dotnetspark.com  
 

Numeric textbox with Ajax in ASP.NET.

sometime we need textbox that's only insert numeric value in asp.net. Yes we can achieve this with so many ways one approach is using JavaScript onkeypress event. Another approach is using regular expression valiator and assign the regular expression.

But we have now Ajax Extenders control available in asp.net and with just setting some property to the textbox and that it you text box now only accept Numeric value. Also we can set some Mask also like only date time format or some currency format.

Lets see how we can achieve this.
First download the AJAX control from here
http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=11121

Now unzip the downloaded files and add reference "AjaxControlToolkit.dll" to your project

Now add this line to you page directives

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

then place one text box in your web page and add extender like this



   

Similarly you can also masked the textbox value. Suppose you want to insert hyphen after 3 character and again after 2 character automatically when user typing the value you can achieve that also with this masked text box in as.net

Let's See an example.


   
 

The above example good to user where user can enter social security number.Similarly you can change the Mask property of the ajax extender depend upon your requirement.

And now you are done now it will accept only numeric value with maximum of 8 similarly you can also choose Datetime,Date,Time etc with this control.

Cheers
Pankaj


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend