Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
.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
  #1 (permalink)  
Old June 2nd, 2006, 08:46 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old June 5th, 2006, 12:24 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Is this a windows or web app?

  #3 (permalink)  
Old June 8th, 2006, 04:00 AM
Authorized User
 
Join Date: Jun 2006
Location: Hyderabad, AP, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #4 (permalink)  
Old June 8th, 2006, 05:43 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #5 (permalink)  
Old June 8th, 2006, 08:46 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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.

  #6 (permalink)  
Old June 8th, 2006, 11:53 PM
Authorized User
 
Join Date: Jun 2006
Location: Hyderabad, AP, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #7 (permalink)  
Old June 9th, 2006, 03:09 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #8 (permalink)  
Old June 18th, 2006, 09:37 AM
Authorized User
 
Join Date: Jun 2006
Location: Hyderabad, AP, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
---------------
  #9 (permalink)  
Old March 22nd, 2007, 09:05 AM
Authorized User
 
Join Date: Mar 2007
Location: Pune, Maharashtra, India.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there a similar funtion in C#.net i.e., like IsNumeric or Not IsNumeric

Please Help with C# Windows Programming code

  #10 (permalink)  
Old March 29th, 2007, 07:50 AM
Registered User
 
Join Date: Mar 2007
Location: satna, madhya pradesh, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vinay_shrivastava03
Default

I want to search
how to print variable on form VB.NET


Similar Threads
Thread Thread Starter Forum Replies Last Post
keypress event kau_shuk VB.NET 2002/2003 Basics 1 July 31st, 2006 11:21 AM
how can use keypress event in a web application? agnihotrived .NET Framework 2.0 2 April 24th, 2005 09:14 PM
KeyPress event jbenson001 VB.NET 2002/2003 Basics 1 March 24th, 2005 04:52 PM
Keypress Event bharatsaboo VB.NET 2002/2003 Basics 0 February 25th, 2005 03:34 AM
KeyPress Event in VB different from VBA PaulG Beginning VB 6 3 February 3rd, 2004 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.