radgrid custom filter template with clientside events disable another js events

2 posts, 0 answers
  1. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 12 Dec 2012 Link to this post

    I create a server control that create programmatically a grid  with template columns, filter templates , ecc.
    Evrithing works fine, but i noticed that when i introduced the MyFilterTemplate class to generate the filter items for any column, if the item (radcombobox, raddatapicker, ecc) include a clientside event then others controls outside the grid  doesn't work propertly.
    For example i have a raddatepicker with a DatePopupButton visible outside the grid , after the page load if i click the popupbutton it shows the popup fine; but after an edit/insert of a value in the grid the popupbutton don't show the popup !.
    So, my question is, how a programatically definition of a filter template column with clientside events may cause undesired operation of others controls..

    This is the code of my filter template class... that as i said before it works perfectly on the grid.

    private class MyFilterColumn : ITemplate
                private Telerik.Web.UI.RadComboBox combo;
                private RadDatePicker _rdp;
                protected CommonParameters.GridTemplateColumnType type;
                protected string fieldvalue;
                protected string fieldtext;
                public MyFilterColumn(string Fieldvalue, string Fieldtext, CommonParameters.GridTemplateColumnType Type)
                    fieldvalue = Fieldvalue;
                    fieldtext = Fieldtext;
                    type = Type;               
                public void InstantiateIn(Control container)
                    switch (type)
                        case CommonParameters.GridTemplateColumnType.ComboOnDemand:
                                combo = new Telerik.Web.UI.RadComboBox();
                                combo.ID = String.Format("RadComboBox{0}", fieldtext);
                                combo.AppendDataBoundItems = true;
                                if (fieldvalue.Length > 0)
                                    combo.DataTextField = fieldtext.Substring(fieldtext.IndexOf(".") + 1, (fieldtext.Length - (fieldtext.IndexOf(".") + 1)));
                                combo.DataValueField = fieldvalue;
                                combo.EmptyMessage = "niente";
                                combo.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("Tutti"));
                                combo.Enabled = true;
                                combo.DataBound += combo_DataBound;
                                combo.DataBinding += new EventHandler(combo_DataBinding);
                                combo.OnClientSelectedIndexChanged = String.Format("ClientComboFilterSelected_{0}", fieldvalue);
                        case CommonParameters.GridTemplateColumnType.Date:
                                _rdp = new RadDatePicker();
                                _rdp.ID = "rdpf" + fieldvalue;
                                _rdp.Width = new System.Web.UI.WebControls.Unit(CommonParameters.RadDatePickerWidth);
                                _rdp.DbSelectedDate = _rdpf_DataBinding((GridItem)container.NamingContainer);
                                string script = "function ClientDataPickerFilterSelected_" + fieldvalue + "(sender,args) {var tableView=$find(\""
                                + ((GridItem)container.NamingContainer).OwnerTableView.ClientID + "\"); var date= FormatSelectedDate(sender);if (date != '') {  alert('data:' + date); tableView.filter(\""
                                + fieldvalue + "\",date,\"EqualTo\");} else { tableView.filter(\"" + fieldvalue + "\",date,\"NoFilter\");  }   }";
                                // tableView.filter(\"" + fieldvalue + "\" ,date,\"NoFilter\");
                                _rdp.ClientEvents.OnDateSelected = script;
                            } break;
                DateTime? _rdpf_DataBinding(GridItem pGriditem)
                    if ((pGriditem).OwnerTableView.GetColumn(fieldvalue).CurrentFilterValue == string.Empty)
                        return new DateTime?();
                        return DateTime.Parse((pGriditem).OwnerTableView.GetColumn(fieldvalue).CurrentFilterValue);
                void combo_DataBinding(object sender, EventArgs e)
                    combo.DataSource = GetData();
                public IList GetData()
                    IList mydata;
                    using (DMWEntities ctx = new DMWEntities())
                        mydata = (from c in ctx.Cli_for
                                  orderby c.Denominazione
                                  select new { IdFornitore = c.IdCLiFor, c.Denominazione }).ToList();
                    return mydata;
                void combo_DataBound(object sender, EventArgs e)
                    Page page = HttpContext.Current.Handler as Page;
                    Telerik.Web.UI.RadComboBox combo = (Telerik.Web.UI.RadComboBox)sender;
                    GridItem container = (GridItem)combo.NamingContainer;
                    string script = "function ClientComboFilterSelected_" + fieldvalue + "(sender,args) {var tableView=$find(\""
                        + ((GridItem)container).OwnerTableView.ClientID + "\");if (tableView)alert(args.get_item().get_value());tableView.filter(\""
                        + fieldvalue + "\",args.get_item().get_value(),\"EqualTo\");}";
                    ScriptManager.RegisterStartupScript(page, page.GetType(), String.Format("ClientComboFilterSelected_{0}", fieldvalue), script, true);
                    combo.SelectedValue = container.OwnerTableView.GetColumn(fieldvalue).CurrentFilterValue;
  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 17 Dec 2012 Link to this post

    Hi Francesco,

    Could you please inspect your request when trying to open the Calendar component for second time and verify if any js errors appear on the page?

    Kind regards,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. DevCraft R3 2016 release webinar banner
Back to Top