Thursday, August 8, 2013

How to use Ajax FilteredTextBoxExtender control in Asp.net OR Ajax FilteredTextBoxExtender Example

Introduction: In this post I will explain how we can use the Ajax FilteredTextBoxExtender control in Asp.net.
FilteredTextBoxExtender
FilteredTextBoxExtender

Description:

FilteredTextBoxExtender used to prevent the user to enter invalid characters to Textbox. FilteredTextBoxExtender Properties:
TargetControlID: ID of Textbox for FilteredTextBoxExtender to operate on
FilterType: Filter type apply on Textbox, as a comma seprated combination of Numbers, Uppercase Letters, Lowercase Letters and Custom.
ValidChars: If Filtertype is Custom than use this property otherwise ignore.

Note: To make spaces between characters Example below given:
 FilterType="LowercaseLetters,Custom" ValidChars=" "

Add a web form to project. Drag and drop the control from Toolbox and design .aspx as mention below:

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <table>
        <tr><td style="font-size:18px; font-weight:bold">Ajax FilteredTextBoxExtender Example</td></tr>
        <tr><td><b>Numeric with *+-/() (Custom Example):</b></td><td><asp:TextBox ID="txtcustom" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtcustom" FilterType="Custom,Numbers" ValidChars="+-=/*().">
        </asp:FilteredTextBoxExtender></td></tr>
        <tr><td><b>Enter Phone Number (Number Example)</b>:</td><td>
            <asp:TextBox ID="txtphone" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender
                ID="FilteredTextBoxExtender2" runat="server" TargetControlID="txtphone" FilterType="Numbers">
            </asp:FilteredTextBoxExtender>
        </td></tr>
        <tr><td><b>Enter Your First Name (Uppercase Example)</b>:</td><td>
            <asp:TextBox ID="txtname" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender
                ID="FilteredTextBoxExtender3" runat="server" TargetControlID="txtname" FilterType="UppercaseLetters">
            </asp:FilteredTextBoxExtender>
        </td></tr>
        <tr><td><b>Enter Your Last Name (Lowercase Example)</b>:</td><td>
            <asp:TextBox ID="txtlastname" runat="server"></asp:TextBox><asp:FilteredTextBoxExtender
                ID="FilteredTextBoxExtender4" runat="server" TargetControlID="txtlastname" FilterType="LowercaseLetters,Custom" ValidChars=" "
> 
            </asp:FilteredTextBoxExtender>
        </td></tr>
        </table>

Run the project and check the result.

No comments:

Post a Comment