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.
Author |
Topic |
messi
Starting Member
47 Posts |
Posted - 2008-10-19 : 13:45:58
|
hey allI 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. |
|
|
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 |
|
|
messi
Starting Member
47 Posts |
Posted - 2008-10-19 : 17:21:54
|
Thanks Afrika for your solveand thank you visakh16 for your help.. |
|
|
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 |
|
|
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 ? |
|
|
|
|
|