8 April 2014

Clear All Text Box Using Loop without Using TextBox Name in c#.net



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace adi.Web
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            ClearAllTextBox(Page.Controls);
        }
        public void ClearAllTextBox(ControlCollection ctrls)
        {
            foreach (Control ctrl in ctrls)
            {
                if (ctrl is TextBox)
                    ((TextBox)ctrl).Text = string.Empty;
                ClearAllTextBox(ctrl.Controls);
            }
        }
    }
}

No comments:

Post a Comment