Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to create numeric textbox, which is retrieve numeric type value only and accepts only numeric values. For example we create textbox in asp.net we retrieve the values use TextBox1.Text, at the same time we get the numeric values, We should give
Convert.ToDouble(TextBox1.Text). So How to get the numeric value without giving Convert.Todouble() function, like TextBox1.NText which is giving numeric value. How to create it. Please anybody help me.

Thanking u
Posted
Comments
walterhevedeich 10-May-12 1:39am    
Really? TextBox class has a NText property?
Sergey Alexandrovich Kryukov 10-May-12 1:42am    
:-)
Sergey Alexandrovich Kryukov 10-May-12 1:42am    
What have you done so far? What's the problem?
--SA

You could create a custom control which either derives from a textbox, or encapsulates a textbox and contains an AsDouble property which does the conversion. It's a sledgehammer to crack a teeny tiny nut though.
Alternatively, you could use Google: Numeric textbox asp.net[^] - there are quite a few out there which also restrict the input to numeric values.
 
Share this answer
 
create numeric textbox
Method 1: Mask your textbox to only accept numbers. It will not take any alphabet or special characters as input through UI. You can do this using Regular expression & Javascript
Method 2: Create a custom control that looks like a textbox but only takes numbers. Expose a NText property to it that will give you the number equivalent of the text entered.
Method 3: Change the behaviour of your existing normal textbox. Override the .Text method or method and put your logic of only extracting numbers from whatever was entered and return back that result.

Try anything based on your ease and requirement.
 
Share this answer
 
v3
Comments
devausha 10-May-12 1:56am    
I want to create Numeric TextBox using Method2. But I didn't know how to create NText Property. Please help me.
Already I am using Custom Controls, But this is not have NText Property, It has only NumberofInteger,NumberofFraction Property.
Sandeep Mewara 10-May-12 2:07am    
Add the new property and handle it in get-set.

Read about Custom controls then.

Look this video: www.youtube.com/watch?v=U44q2fdgWu0
Example CustomTextbox control: http://www.codeproject.com/Articles/15637/ASP-NET-Required-TextBox-Graphical-RequiredFieldVa
devausha 10-May-12 2:15am    
Thank you So much
Sandeep Mewara 10-May-12 2:33am    
Welcome.
 
Share this answer
 
Comments
devausha 10-May-12 1:51am    
I refer this site. It is used for accepts only numeric values. But I also want to get only numeric values. When I save, If the numeric textbox is empty, the error occured, 'Could not convert nvarchar to numeric'. So,
If I save without value in the numeric textboxes it automatically get 0 value. How to change the code in that article. Please help me.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900