Clearing form which contain telerik controls

3 posts, 0 answers
  1. DK
    DK avatar
    72 posts
    Member since:
    Jun 2009

    Posted 29 Jul 2009 Link to this post

    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. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 04 Feb 2013 Link to this post

    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 ...
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 04 Feb 2013 Link to this post

    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;
            }
        }
    }
Back to Top