In this article I will explain with multiple examples how to use the ASP.Net AJAXControlToolkit FilteredTextBoxExtender control.
Using the ASP.Net AJAX FilterTextBoxExtender control
1. Drag an ASP.Net AJAX ScriptManager on the page.
2. Register the AJAX Control Toolkit Library after adding reference to your project.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
3. Add the FilteredTextBoxExtendercontrol and set its TargetControlID with the ID of the TextBox you want to filter the input.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" FilterType="Numbers"
TargetControlID="TextBox1" />
That’s it done. Now below I’ll show you the different cases how you can configure the ASP.Net AJAX FilteredTextBoxExtendercontrol.
Allow only Numbers i.e. Digits 0 – 9
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" FilterType="Numbers"
TargetControlID="TextBox1" />
Allow only Alphabets (Both Uppercase and Lowercase)
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" FilterType="LowercaseLetters, UppercaseLetters"
TargetControlID="TextBox2" />
Allow only Uppercase Alphabets
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server" FilterType="UppercaseLetters"
TargetControlID="TextBox3" />
Allow only Lowercase Alphabets
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" FilterType="LowercaseLetters"
TargetControlID="TextBox4" />
Allow Alphabets and Numbers (Alphanumeric and no special characters)
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" runat="server" FilterType="Numbers, UppercaseLetters, LowercaseLetters"
TargetControlID="TextBox5" />
Email Address (Lower case alphabets, numbers, @ and dot)
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender5" runat="server" FilterType="Numbers, LowercaseLetters, Custom"
ValidChars=".@" TargetControlID="TextBox6" />
Decimal Number (Digits and dot)
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender7" runat="server" FilterType="Numbers, Custom"
ValidChars="." TargetControlID="TextBox7" />
Money or Currency (Digits, comma and dot)
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender8" runat="server" FilterType="Numbers, Custom"
ValidChars=".," TargetControlID="TextBox8" />
Demo
Downloads