You can call this function to clear content of controls such as TextBox, CheckBox and DropDownList. You can further add on other ASP.Net controls to clear their content.
public void ClearFields(System.Web.UI.Page page, string defaultDropDownValue) { ArrayList all = GetControls(page.Controls); for (int i = 0; i <= all.Count - 1; i++) { Control ctl = (Control)all[i]; if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) ((TextBox)ctl).Text = ""; //to Uncheck All Check Box if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox")) ((CheckBox)ctl).Checked = false; //to set dropdown default value try { if (ctl.GetType().ToString().Equals("System.Web.UI.WebControls.DropDownList")) ((DropDownList)ctl).SelectedValue = defaultDropDownValue; } catch { } } }
Many Asp.Net new programmer do it by clear control content by setting their property one by one . For Ex.
TextBox1.Text="";
checkBox1.checked=False;
Comments
Post a Comment