Add FilteredTextBoxExtender problem RRS feed

  • Question

  • User1510859543 posted

    I am trying to add a FilteredTextBoxExtender via code in a ListView and it is not working (not throwing error either).  My code is below. Am I missing something?  Thanks.

        Protected Sub lvSchedule_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lvSchedule.ItemDataBound
                    Dim fextender As AjaxControlToolkit.FilteredTextBoxExtender = New AjaxControlToolkit.FilteredTextBoxExtender
                    Dim tb As TextBox = CType(lvSchedule.FindControl("txtCarbLiquid"), TextBox)
                    fextender.FilterMode = AjaxControlToolkit.FilterModes.ValidChars
                    fextender.ValidChars = "0123456789"
                    fextender.TargetControlID = tb.ID
        END Sub

    Thursday, January 29, 2015 2:49 PM

All replies

  • User2103319870 posted

    You need to have Ajax ToolkitScriptManager prior to using filter extender. Also instead of adding the filterexteder control from code behind you can add from aspx page like given below

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        <asp:ListView ID="ListView1" runat="server" GroupPlaceholderID="groupPlaceHolder1" DataSourceID="SqlDataSource1"
                <table border="1" width="50%">
                        <td style="width: 50%">
                            <asp:TextBox ID="txtCarbLiquid" Text='<%#Eval("AddressID") %>' runat="server"></asp:TextBox><br />
                            <asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtCarbLiquid" FilterMode="ValidChars" ValidChars="0123456789" runat="server">
                        <td style="width: 50%">
                            <asp:Label ID="LabelDOB" runat="server" CssClass="Label" Text='<%#Eval("AddressLine1") %>' /><br />
                    <asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
                    <asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorks2008R2ConnectionString %>"
            DataSourceMode="DataReader" SelectCommand="SELECT top 10 [AddressID], [AddressLine1], [AddressLine2] FROM Person.[Address]">

    Thursday, January 29, 2015 3:08 PM
  • User1510859543 posted

    I do have the ToolkitScriptManager but it is on the master page. Does that matter?  I don't think I can have it on both master and content page.  I need to do it in code because I am exporting the ListView into html and sending on email and it fails if I use the filter directly on the aspx page.

    Thursday, January 29, 2015 3:14 PM
  • User1918509225 posted

    Hi dlchase,

    Yes you are right ,you just can have only one TookitScriptManager  in your page.

    FilteredTextboxExtender is used  to restrict what kind of value you can type in your textbox.

    It seems that it 's not  related with exporting the listview  into html.

    Could you explain more details on your error when you export listview into html ?

    Best Regards,

    Kevin Shen.

    Friday, January 30, 2015 4:11 AM
  • User1510859543 posted

    I get the following exception error.

    An unhandled exception occurred:
    Message: Extender control 'FilteredTextBoxExtender1' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors().
    Parameter name: extenderControl

    It happens in code-behind where I am saving a DIV (called mainDiv) content to html for inserting into an email that goes out to a client.  The error comes from the following code.

            Dim sw As New StringWriter()
            Dim w As New HtmlTextWriter(sw)
            Dim s As String = sw.GetStringBuilder().ToString()

    Friday, January 30, 2015 8:12 AM
  • User1510859543 posted

    Must have stumped everyone on this.

    Thursday, February 5, 2015 4:44 PM