Wednesday, October 23, 2013

How to use Ajax FilteredTextBoxExtender

Did you ever think of getting a ready made textbox with validation in ASP.NET? In this article I am going to explain you an Ajax control names FilteredTextBoxExtender. This control will help you to filter the user input without any additional script or coding.

Advantage of FilteredTextBoxExtender is there is not much configuration required. IT has only few properties.

1. TargetControlID—> You may specify the control you wanted to filter.

2. FilterType—> Here you mention what kind of filter you want to apply on your textbox control.

3. ValidChars—>As it’s name suggests you may enter the valid characters user supposed to enter in your textbox.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FilteredTextbox.aspx.cs" Inherits="Blog.FilteredTextbox" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Please Enter Only Numeric Value"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <ajaxToolkit:FilteredTextBoxExtender ID="TextBox1_FilteredTextBoxExtender" runat="server" Enabled="True" TargetControlID="TextBox1" ValidChars="0123456789" FilterType="Numbers">
        </ajaxToolkit:FilteredTextBoxExtender>
    </div>
    </form>
</body>
</html>
Output will be like below,
FilterType="LowercaseLetters"

LowerCase

FilterType="UppercaseLetters"

UppercaseLetters

FilterType="Numbers"

Numbers

Hope you enjoyed this article. As usual your comments are always welcome.

No comments: