使用VB在asp.net的文本框中仅接受数字 [英] Accept only number in a text box in asp.net with VB
问题描述
在输入数据到文本框时,它应该只接受数字并且不接受任何文本..所以应该怎么做...请回复..
while entering data to text box it should only accept the numbers and no text should be accepted.. so how should this be done... please do reply..
推荐答案
在输入数据到文本框时,它应该只接受数字并且不接受任何文本..那么应该如何完成...请回复..
while entering data to text box it should only accept the numbers and no text should be accepted.. so how should this be done... please do reply..
你好,试试这个......在离开中控制
dim tx_Value as
如果txt_Box.text = space(0)则
退出sub $ / $
endif
试试
tx_value = txt_Box.text
catch
msgbox(此文本框仅接受数字)
结束尝试
再见
Hello, try this ... at the "Leave" of the control
dim tx_Value as long
if txt_Box.text = space(0) then
exit sub
endif
try
tx_value = txt_Box.text
catch
msgbox("this text box only accept numbers")
end try
Bye
您是否试图让用户输入他们想要的内容,然后使用服务器上的代码检查无效数据?
或
您是否试图阻止用户首先输入信息?
如果第二种情况是你想要做的,我相信你必须使用JavaScript来防止文本被输入。这意味着你必须开发一个客户端脚本,它不会允许输入与你期望的类型不匹配。请注意,某些用户可以绕过此检查,因此建议您验证服务器端逻辑中的数据。
无法真正阻止用户输入某些文本这使用纯.NET;但是,Microsoft为.NET开发了一个很好的扩展,可以为您过滤文本框。如果您有兴趣,请查看Microsoft提供的软件包: ASP.NET AJAX
干杯!
-Frinny
Are you trying to let your user enter whatever they''d like and then checking for invalid data using code on the server ?
Or
Are you trying to prevent the user from even entering in the information in the first place?
If the second case is what you''re trying to do, I believe that you will have to use JavaScript to prevent the text from ever being entered. This means you''ll have to develop a client side script that simply will not allow input that doesn''t match the type you''re expecting. Be aware that some users can by-pass this check so it is advisable to also validate the data in your server side logic.
There is no way to really prevent users from entering certain text this using pure .NET; however, there is a nice extension developed by Microsoft for .NET that will filter your textboxes for you. If you''re interested, check out the package offered by Microsoft called: ASP.NET AJAX
Cheers!
-Frinny
输入数据到文本框时,它应该只接受数字,不应该接受任何文本..所以应该怎么做...请回复..
while entering data to text box it should only accept the numbers and no text should be accepted.. so how should this be done... please do reply..
尝试在文本框的KeyPress事件中粘贴此代码
如果Asc(e.KeyChar) > = 48和Asc(e.KeyChar)< = 57然后
e.Handled = False
ElseIf Asc(e.KeyChar)= 46然后>
e.Handled = False
否则
e.Handled = True
结束如果
谢谢和问候,
Prashant Hirapara
Hi,
Try paste this code in the KeyPress event of the text box
If Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Then
e.Handled = False
ElseIf Asc(e.KeyChar) = 46 Then
e.Handled = False
Else
e.Handled = True
End If
Thanks and Regards,
Prashant Hirapara
这篇关于使用VB在asp.net的文本框中仅接受数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!