asp.net中的FilteredTextBoxExtender

时间:2011-11-04 00:27:37

标签: asp.net ajax

iam在asp.net 3.5中使用ajaxtoolkit,使用过滤器texbox扩展器控件

                            <%@ Page Language="C#" %>
                        <%@ Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit"
                        Assembly="AjaxControlToolkit" %>
                        <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN"
                        “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                        <html xmlns="http://www.w3.org/1999/xhtml">
                        <head runat="server">
                        <title>Show Filtered TextBox</title>
                        </head>
                        <body>
                        <form id="form1" runat="server">
                        <div>
                        <asp:ScriptManager ID="ScriptManager1" runat="server" />
                        <asp:Label
                        id="lblNumeric"
                        Text="Enter a Number:"
                        AssociatedControlID="txtNumeric"
                        Runat="server" />
                        <br />
                        <asp:TextBox
                        id="txtNumeric"
                        Runat="server" />
                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtNumeric" FilterType="Numbers">
                            </ajaxToolkit:FilteredTextBoxExtender>   
                        <br /><br />
                        <asp:Label
                        id="lblProductCode"
                        Text="Enter a Product Code:"
                        AssociatedControlID="txtProductCode"
                        Runat="server" />
                        <br />
                        <asp:TextBox
                        id="txtProductCode"
                        Runat="server" />

                        <br />
                        (A product code can contain only lower-case characters,
          ![enter image description here][1]              underscores, exclamation marks, and no spaces)
                        </div>
                        </form>
                        </body>
                        </html>

我使用扩展器控件..witfiltertype作为数字..但是在运行时不工作,它接受所有字符.. 任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您正试图让您的代码更复杂。实际上FilterTypeExtender非常容易使用。按照这种方式。 [注意:正确关闭相应的控件。]

<asp:TextBox ID="txtExperienceYears" runat="server" Width="223px" MaxLength="2"></asp:TextBox>
                        <%-- Now add the FilterTypeExtender below --%>
                        <asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtExperienceYears" FilterType="Numbers"></asp:FilteredTextBoxExtender>