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

Clearing form which contain telerik controls

2 Answers 132 Views
Input
This is a migrated thread and some comments may be shown as answers.
DK
Top achievements
Rank 2
DK asked on 29 Jul 2009, 05:48 AM
I have a master page which contains the form tag

now on the content page i have radtextbox,radnumbericboc.raddatepicker,radcombobox,checkbox and radio button.

i have a buton called clear on the content page.
now onclientClick event of the buton i want to clear the fileds in the content page.

i dont want to do  manually each fileds like setting txtabc.text=""; etc.
just want to clear form by using loops.

please help me as soon as possible.

thnaks in advance

2 Answers, 1 is accepted

Sort by
0
Aarsh
Top achievements
Rank 1
answered on 04 Feb 2013, 08:45 PM
Yes, I too am interested to avoid using my copy-paste skills and to let the code look clean and elegent. I have the same setup as 'DK' has mentioned ...
0
Aarsh
Top achievements
Rank 1
answered on 04 Feb 2013, 09:28 PM
Hello @DK,

first of all I aplogize for nacroposting but let me share what I ended up with ...

I just used Linq to use a brand-new new extension method beneath a couple function calles, as depicted:

ControlExtension.All(this.Controls).OfType<RadTextBox>().ToList().ForEach(tb => tb.Text = "");
ControlExtension.All(this.Controls).OfType<RadComboBox>().ToList().ForEach(dd => dd.SelectedIndex = 0);
...

public static class ControlExtension
{
    public static IEnumerable<Control> All (this ControlCollection controls)
    {
        foreach (Control c in controls)
        {
            foreach (Control child in c.Controls.All())
            {
                yield return child;
            }
            yield return c;
        }
    }
}
Tags
Input
Asked by
DK
Top achievements
Rank 2
Answers by
Aarsh
Top achievements
Rank 1
Share this question
or