This is a migrated thread and some comments may be shown as answers.

RadGrid Custom Filter OnTextChanged event got triggered twice

4 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 28 Aug 2015, 06:40 PM

Hi There,

I am using a custom filter in my RadGrid, but when debugging I noticed that the OnTextChanged event got triggered twice. However, if I remove the AjaxSetting section, everything works fine. But I do need to config ajax settings in my application. Is there anyone to explain why this is happening? The following is the demo code. Thanks a lot. 

TestCustomFilter.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" EnableViewStateMac="false" ViewStateEncryptionMode="Never" CodeFile="TestCustomFilter.aspx.cs" Inherits="TestCustomFilter" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head id="Head1" runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="Stylesheet" href="../Styles/styles.css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container size-medium">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
            GridLines="None" AllowPaging="true"
            AllowSorting="true" PageSize="10" AllowFilteringByColumn="true">
            <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst"
                DataKeyNames="OrderID" Dir="LTR" Frame="Border"
                TableLayout="Auto">
                <Columns>
                    <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="OrderID" Display="false"
                        DataType="System.Int32" FilterListOptions="VaryByDataType" ForceExtractValue="None"
                        HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="ShipName" HeaderText="Ship Name" SortExpression="ShipName">
                        <FilterTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"  OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                        </FilterTemplate>
                        <ItemTemplate>
                            <asp:HyperLink ID="targetControl" runat="server" NavigateUrl="#" Text='<%# Eval("ShipName") %>'></asp:HyperLink>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn AllowSorting="true" DataField="ShipCountry" HeaderText="Ship Country"
                        SortExpression="ShipCountry" UniqueName="ShipCountry">
                    </telerik:GridBoundColumn>
                </Columns>
                <PagerStyle PageSizeControlType="RadDropDownList" ShowPagerText="false" />
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

 

 

TestCustomFilter.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Telerik.Web.UI;
using System.IO;
 
public partial class TestCustomFilter : System.Web.UI.Page
{
    public class MyOrder
    {
        public int OrderID { get; set; }
        public DateTime OrderDate { get; set; }
        public double Freight { get; set; }
        public string ShipName { get; set; }
        public string ShipCountry { get; set; }
    }
 
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        LoadData();
    }
 
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        LoadData();
    }
 
    private void LoadData()
    {
        MyOrder _order1 = new MyOrder();
        _order1.OrderID = 1;
        _order1.OrderDate = new DateTime(2014, 1, 18);
        _order1.Freight = 15.61;
        _order1.ShipCountry = "Canada";
        _order1.ShipName = "David";
 
        MyOrder _order2 = new MyOrder();
        _order2.OrderID = 2;
        _order2.OrderDate = new DateTime(2015, 9, 12);
        _order2.Freight = 12.39;
        _order2.ShipCountry = "US";
        _order2.ShipName = "Jack";
 
        MyOrder _order3 = new MyOrder();
        _order3.OrderID = 3;
        _order3.OrderDate = new DateTime(2015, 6, 2);
        _order3.Freight = 6.81;
        _order3.ShipCountry = "Mexico";
        _order3.ShipName = "Howard";
 
        MyOrder _order4 = new MyOrder();
        _order4.OrderID = 4;
        _order4.OrderDate = new DateTime(2014, 3, 26);
        _order4.Freight = 19.92;
        _order4.ShipCountry = "Canada";
        _order4.ShipName = "William";
 
        MyOrder _order5 = new MyOrder();
        _order5.OrderID = 5;
        _order5.OrderDate = new DateTime(2015, 5, 15);
        _order5.Freight = 9.96;
        _order5.ShipCountry = "US";
        _order5.ShipName = "Don";
 
        List<MyOrder> _myList = new List<MyOrder>();
        _myList.Add(_order1);
        _myList.Add(_order2);
        _myList.Add(_order3);
        _myList.Add(_order4);
        _myList.Add(_order5);
 
        RadGrid1.DataSource = _myList;
    }
 
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        TextBox TextBox1 = sender as TextBox;
        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("ShipName");
        column.CurrentFilterFunction = GridKnownFunction.Contains;
        column.CurrentFilterValue = TextBox1.Text.Trim();
        RadGrid1.Rebind();
    }
}

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 02 Sep 2015, 01:22 PM
Hi Don,

I've created a sample RadGrid web site using the provided code snippets. Please run the attached application and let me know about the result.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Don
Top achievements
Rank 1
answered on 02 Sep 2015, 07:04 PM

Hi Eyup,

Thanks for your reply. I tested the sample code you created.  The OnTextChanged event got triggered twice when debugging the application, also the Page_load event got triggered twice. That is why the label displays "TextChanged event fired 1 time", the variable count was set to 0 when the second Page_load fires. Please help. Thank you.

 

0
Accepted
Eyup
Telerik team
answered on 07 Sep 2015, 08:09 PM
Hello Don,

Could you replace the TextBox with a telerik:RadTextBox and let me know if it changes the behavior?
Looking forward to your reply.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Don
Top achievements
Rank 1
answered on 16 Sep 2015, 08:13 PM
Thank you, Eyup. Telerik:RadTextBox ​did the trick.
Tags
Grid
Asked by
Don
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Don
Top achievements
Rank 1
Share this question
or