Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Just Numbers

Author  Topic 

messi
Starting Member

47 Posts

Posted - 2008-10-19 : 13:45:58
hey all

I want to make a text box in Asp.net,that accept numbers only
using C#

how can i do that?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-19 : 13:55:02
just add a client side validation function using javascript to check if txtbox contains any other characters other than number on submission of page.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-19 : 15:51:34
quote:
Originally posted by visakh16

just add a client side validation function using javascript to check if txtbox contains any other characters other than number on submission of page.



In c# ? No Boss

In c# its better to use the validation controls. Everything is done for you. Use the regular expression validator e.g.

<asp:RegularExpressionValidator runat="server" ControlToValidate="Numbers" SetFocusOnError="true" ValidationExpression="([0-9])*" Text="Wrong"></asp:RegularExpressionValidator> 






Or if you want to write some code, use the custom validaor
Go to Top of Page

messi
Starting Member

47 Posts

Posted - 2008-10-19 : 17:21:54
Thanks Afrika for your solve
and thank you visakh16 for your help..
Go to Top of Page

raghulvarma
Starting Member

21 Posts

Posted - 2008-10-20 : 13:12:21
U could use enum so that u could make the textbox to accept only numaric values.As enum are like constants
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-20 : 14:51:33
quote:
Originally posted by raghulvarma

U could use enum so that u could make the textbox to accept only numaric values.As enum are like constants



Why reinvent the wheel ?
Go to Top of Page
   

- Advertisement -