本文介绍了允许用户在文本框中仅输入0或1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
允许用户在文本框中只输入0或1的单个数字。
帮助我们,谢谢。
allow user to enter only a single digit of 0 or 1 in textbox.
help me guys, thanks.
推荐答案
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<cc1:filteredtextboxextender id="FilteredTextBoxExtender1" runat="server" validchars="10" targetcontrolid="TextBox1" >
</cc1:filteredtextboxextender>
问候..
Regards..
protected void YourTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var allowKeys = new[] { Keys.Back, Keys.D0, Keys.D1 };
e.Handled = !allowKeys .Contains((Keys)e.KeyChar);
}
我希望它会对你有所帮助。
$ b $祝你好运。
I hope It will help you.
Good luck.
这篇关于允许用户在文本框中仅输入0或1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!