Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
allow user to enter only a single digit of 0 or 1 in textbox.

help me guys, thanks.
Posted

Use AJAX FilteredTextBoxExtender Control[^] like this:
C#
<asp:textbox id="TextBox1" runat="server"></asp:textbox>

<cc1:filteredtextboxextender id="FilteredTextBoxExtender1"  runat="server" validchars="10" targetcontrolid="TextBox1" >
</cc1:filteredtextboxextender>

Regards..
 
Share this answer
 
v3
Use KeyPress event.

Eg.

C#
protected void YourTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
    var allowKeys = new[] { Keys.Back, Keys.D0, Keys.D1 };
    e.Handled = !allowKeys .Contains((Keys)e.KeyChar);
}


I hope It will help you.

Good luck.
 
Share this answer
 
Comments
Member239258 7-Oct-13 3:18am    
Sir, I want to put these 0 and 1 while editing in gridview.

so how can i do in gridview row editing using asp.net c#
Raje_ 7-Oct-13 3:41am    
Please Check solution 2.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900