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

maxlength property on RadFilterNumericFieldEditor and RadFilterTextFieldEditor

1 Answer 14 Views
Filter
This is a migrated thread and some comments may be shown as answers.
alpesh
Top achievements
Rank 1
alpesh asked on 02 May 2013, 08:38 PM
Hi,

I dont see the maxlength property on RadFilterNumericFieldEditor and RadFilterTextFieldEditor.
Is there a way we can set the maxlength on these items?

Thanks

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 07 May 2013, 07:05 AM
Hi Alpesh,

I have assembled a sample project showing the desired functionality implemented. The idea is to loop through all RadNumericTextBox and TextBox controls in the RadFilter and set their MaxLenght property as shown below.
protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    List<Control> controls = new List<Control>();
 
    FindControlRecursive(this.RadFilter1, controls, typeof(TextBox));
    FindControlRecursive(this.RadFilter1, controls, typeof(RadNumericTextBox));
    foreach (Control control in controls)
    {
        TextBox textBox = control as TextBox;
        RadNumericTextBox numeric = control as RadNumericTextBox;
        if (textBox != null)
        {
            textBox.MaxLength = 2;
        }
        else if (numeric != null)
        {
            numeric.MaxLength = 2;
        }
    }
}
 
public static void FindControlRecursive(Control container, List<Control> controls, Type type)
{
    if (container.GetType() == type)
    {
        controls.Add(container);
    }
 
    if (container.Controls.Count == 0)
    {
        return;
    }
 
    foreach (Control ctrl in container.Controls)
    {
        FindControlRecursive(ctrl, controls, type);
    }
    return;
}

All the best,
Antonio Stoilkov
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.
Tags
Filter
Asked by
alpesh
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or