Focus filteritem

2 posts, 0 answers
  1. Kurt Bilde
    Kurt Bilde avatar
    1 posts
    Member since:
    Dec 2009

    Posted 31 Oct 2011 Link to this post



    I am using radfilter on a radlistview bound to a datasource. On pageload I use the following code to default show the filteritem Name from the datasource:



    if (!IsPostBack)
           RadFilterTextFieldEditor editor = new RadFilterTextFieldEditor();
           if (!IsPostBack)
                  editor.FieldName = "NAME";
                  editor.DataType = typeof(string);
                  RadFilterContainsFilterExpression filter = new RadFilterContainsFilterExpression("NAME");
                  filter.Value = "";


    My question is how I can set the focus on the NAME filteritem on pageload, so the user can start typing the filtertext, instead of manually click the filteritem and then typing the filtertext?


  2. Mira
    Mira avatar
    1124 posts

    Posted 31 Oct 2011 Link to this post

    Hello Kurt Bilde,

    Unfortunately the desired functionality is not supported with theRadFilter control.
    Possible workaround in this case is to use the code below for setting the focus to the latest textbox:
    protected void RadFilter1_PreRender(object sender, EventArgs e)
        var ctrl = ControlsOfType<ITextControl>(RadFilter1).Where(p => p.GetType() != typeof(LiteralControl));
        if (ctrl.Count() > 0)
            (ctrl.Last() as Control).Focus();
    public IEnumerable<T> ControlsOfType<T>(Control parent) where T : class
        foreach (Control control in parent.Controls)
            if (control is T)
                yield return control as T;
            foreach (T descendant in ControlsOfType<T>(control))
              yield return descendant;

    I hope this works for you.

    All the best,
    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. Telerik UI for ASP.NET Core is out
Back to Top