Tuesday, February 7, 2012

Control Clear for the Pages

BaseUtility.PageControlsClear(this.Page);  --Called from test.aspx.cs page
(here BaseUtility is the class file).
 BaseUtility.CS Page :

public static void PageControlsClear(Page currentPage)
        {
            List<Control> allControls = new List<Control>();
            GetControlList<Control>(currentPage.Controls, allControls);

            foreach (var childControl in allControls)
            {
                if (childControl.GetType() == typeof(TextBox))
                    ((TextBox)childControl).Text = string.Empty;
                if (childControl.GetType() == typeof(DropDownList))
                    ((DropDownList)childControl).ClearSelection();
                if (childControl.GetType() == typeof(CheckBox))
                    ((CheckBox)childControl).Checked = false;
                if (childControl.GetType() == typeof(CheckBoxList))
                    ((CheckBoxList)childControl).ClearSelection();
            }
        }

No comments:

Post a Comment

Comments

Search

Custom Search
Protected by Copyscape Plagiarism Software