 |
| .NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 2nd, 2006, 08:46 PM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ASCII code on keypress event
Hai
I have a text box in which when a key is pressed, i have to check if it is a number or not. The idea i had was to check with ASCII codes for numbers. if anyone Could provide a solution for thsi problem it would be great of them.
Ash
ashok
|
|

June 5th, 2006, 12:24 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Is this a windows or web app?
|
|

June 8th, 2006, 04:00 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
VB.NET
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar >= Chr(48) And e.KeyChar <= Chr(57) Then
MsgBox(e.KeyChar.ToString)
End If
End Sub
|
|

June 8th, 2006, 05:43 AM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It is a Web Application and the code
If e.KeyChar >= Chr(48) And e.KeyChar <= Chr(57) Then
MsgBox(e.KeyChar.ToString)
End If
isnt working
do i have to import any name spaces
Thanks and regards
ashok
ashok
|
|

June 8th, 2006, 08:46 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
You need to use javascript for this. Are you just trying to validate that the user only enters a numeric value? If so, use the compare validator.
|
|

June 8th, 2006, 11:53 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi...
The previous code was for WindowsApplication
This one is for Web Application
Anyway, let us assume that u are taking input in a textbox in a web app. First set AutoPostBack to True
Then wirte the following code in the event OnTextChanged
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim str As String
str = TextBox1.Text
If Not IsNumeric(str) Then
Response.Write("Enter a Number !!! ")
TextBox1.Focus()
End If
End Sub
On Losing focus OR On submitting, it will check it a number is entered. Or alternately as Benson suggested, use a CompareValidator
Regards
|
|

June 9th, 2006, 03:09 AM
|
|
Registered User
|
|
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Shyam Bharath
Thanks for the code. This code is getting executed only if an event occurs on the page. This is not happening on keypress. Is thare any way to handle on key press.Thanks for the reply. It would be great to read again from you.
Ashok
ashok
|
|

June 18th, 2006, 09:37 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am sorry...There is unfortunately no event handler either in .net 1.x or in .net 2.x for that
This might be because ecmascript does not support keypress in standard HTML textboxes. We may have to wait for some future version of ecmascript to support that.
---------------
The .NET Underground Portal
www.pureportals.com/developers
---------------
|
|

March 22nd, 2007, 09:05 AM
|
|
Authorized User
|
|
Join Date: Mar 2007
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is there a similar funtion in C#.net i.e., like IsNumeric or Not IsNumeric
Please Help with C# Windows Programming code
|
|

March 29th, 2007, 07:50 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I want to search
how to print variable on form VB.NET
|
|
 |