清空指定頁面上所有的控制項內容

  • 5436
  • 0
  • C#
  • 2013-09-25

清空指定頁面上所有的控制項內容

   //protected void btnClearAll_Click(object sender, EventArgs e)
    //{
    //    rquVtrSettle_Month.Enabled = false;
    //    ClearAllContent(this.Page);
    //    rquVtrSettle_Month.Enabled = true;
    //}
 
    #region "清空指定頁面上所有的控制項內容"
    public static void ClearAllContent(System.Web.UI.Control page)
    {
        int nPageControls = page.Controls.Count;
        for (int i = 0; i < nPageControls; i++)
        {
            foreach (System.Web.UI.Control control in page.Controls[i].Controls)
            {
                {
                    if (control is TextBox)
                        (control as TextBox).Text = "";
                    if ((control is Label ) && ((control as Label).ID == "lblMsg"))
                        (control as Label).Text  = "";
                }
            }//foreach 
        }//for 
    }
    #endregion