Clear all controls in Asp.net

public static void ClearAllControls(Control PageObject)
        {
            foreach (Control ctrControl in PageObject.Controls)
            {
                if (object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox)))
                    ((TextBox)ctrControl).Text = string.Empty;

                if (object.ReferenceEquals(ctrControl.GetType(), typeof(DropDownList)))
                    ((DropDownList)ctrControl).SelectedIndex = -1;

                ClearAllControls(ctrControl);
            }
        }
Call Controlprocedure using below code
ClearAllControls(this);
Note in the above code I have only involved TextBox and DropDownList Controls, likewise you can use your own.
Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More