Wrox Programmer Forums
|
Visual Web Developer 2005 Discuss creating ASP.NET 2.0 sites with Microsoft's Visual Web Developer 2005. If your question is more specific to a piece of code than the Visual tool, see the ASP.NEt 2.0 forums instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Web Developer 2005 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
 
Old December 15th, 2009, 10:34 PM
Registered User
 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Key Press event in vb.net 2005

Hi,

I'm new to .NET, I have a Numeric text box want to accept only numbers. I have put code into KeyDown and KeyPress event. But events are not triggering at all. Any help please?

Below is the code:
<code>
Private Sub txtNumber_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNumber.KeyDown
blnNumericNo = False
If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
If e.KeyCode <> Keys.Back Then
blnNumericNo = True
End If
End If
End Sub

Private Sub txtNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumber.KeyPress
' Debug.Print(e.KeyChar)
If Not blnNumericNo Then

e.Handled = True
End If
End Sub

</code>

Last edited by prabhubasoor; December 15th, 2009 at 10:37 PM..
 
Old January 20th, 2010, 10:09 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

You can check the code after input with a regex command

Or check input with javascript as keys are pressed.
I use the following to convert a user name to uppercase dynamically.
It can look a little weird in practice as it always puts the focus at the end of the field but it works.


<asp:TexBox ID="UserName" runat="server" onChange="changeToUpperCase(this.id")
onyeyup="changeToUpperCase(this.id) " > < /asp:textbox>


<script language="Javascript" type="text/javascript">
function changeToUpperCase(UserName)
{
document.getElementId(UserName).value = document.getElementId(UserName).value.toUpperCase( );
}


You will need to change the to uppercase bit to allow only numbers.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulating a key press with c++ Bourne C++ Programming 2 April 13th, 2007 02:03 PM
Key press problem diegoblin Beginning VB 6 3 October 5th, 2006 02:10 PM
TAB KEY working together KEY PRESS event thomaz C# 4 August 20th, 2006 02:47 PM
key press event in webforms agnihotrived ADO.NET 4 March 19th, 2005 03:22 PM
Force a Key Press? ashley_y VB How-To 2 January 9th, 2004 03:59 PM





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