Asp.Net Ajax FilteredTextBox Extender Example

This Example explains how to use Asp.Net Ajax FilteredTextbox Extender to filter entries Or create numeric /Letters only textbox

Asp.net ajax filteredTextBoxExtender Example
By using it we can restrict user from entering certain special characters in text only or deny character entries in numeric textbox.

I have placed four textbox on the page.

1st will allow UPPERCASE letters

2nd allow lowercase

3rd will allow only Numbers

4th is custom textbox and it only allow "123abc$%" characters.

We can also use JavaScript Or RegularExpression Validator to achieve same functionality.


HTML SOURCE OF PAGE
   1:  <asp:ToolkitScriptManager ID="ToolkitScriptManager1" 
   2:                            runat="server">
   3:  </asp:ToolkitScriptManager>
   4:   
   5:  <asp:TextBox ID="txtUpperCase" runat="server"/>
   6:  <asp:FilteredTextBoxExtender ID="UpperCase" 
   7:                 runat="server" 
   8:                 TargetControlID="txtUpperCase" 
   9:                 FilterType="UppercaseLetters">
  10:  </asp:FilteredTextBoxExtender>
  11:              
  12:  <asp:TextBox ID="txtLowerCase" runat="server"/>
  13:  <asp:FilteredTextBoxExtender ID="LowerCase" 
  14:               runat="server" 
  15:               TargetControlID="txtLowerCase" 
  16:               FilterType="LowercaseLetters">
  17:  </asp:FilteredTextBoxExtender>
  18:   
  19:  <asp:TextBox ID="txtNumbers" runat="server"/>
  20:  <asp:FilteredTextBoxExtender ID="Numbers" 
  21:               runat="server" 
  22:               TargetControlID="txtNumbers" 
  23:               FilterType="Numbers">
  24:  </asp:FilteredTextBoxExtender>
  25:   
  26:  <asp:TextBox ID="txtCustom" runat="server"/>
  27:  <asp:FilteredTextBoxExtender ID="Custom" 
  28:               runat="server" 
  29:               TargetControlID="txtCustom" 
  30:               FilterType="Custom" 
  31:               ValidChars="123abc$%">
  32:  </asp:FilteredTextBoxExtender>

To restrict certain or special characters, we can configure as follows.

   1:  <asp:TextBox ID="TextBox1" runat="server"/>
   2:  <asp:FilteredTextBoxExtender ID="Custom" 
   3:               runat="server" 
   4:               TargetControlID="TextBox1" 
   5:               FilterMode="InvalidChars" 
   6:               InvalidChars="!@#$%^&amp;*()~?><|\';:">
   7:  </asp:FilteredTextBoxExtender>

We can change FilteredTextboxExtender properties in code behind if we need to allow or change textbox type on runtime.

using AjaxControlToolkit;
txtUpperCase_FilteredTextBoxExtender.FilterType = FilterTypes.Custom;
txtUpperCase_FilteredTextBoxExtender.FilterMode = FilterModes.ValidChars;
txtUpperCase_FilteredTextBoxExtender.ValidChars = "1234567890";


Hope this helps.

Download Sample Code



If you like this post than join us or share

0 comments:

Find More Articles