Wednesday 28 December 2011

How To Clear All Textboxes and Dropdownlist in ASP.NET




protected void BtnCancel_Click(object sender, EventArgs e)
    {
        Control myForm = Page.FindControl("iii");

        foreach (Control ctl in myForm.Controls)
        {
            if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
            {
                ((TextBox)ctl).Text = "";
            }
            else if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.DropDownList"))
            {
                ((DropDownList)ctl).ClearSelection();
            }
        }
    }




No comments: