Posts

Showing posts with the label Reset Text Box

Reset Text Boxes in ASP.Net - Part 2

In my last Article " Reset Text Boxes in ASP.Net " I suggested a way to clear all text boxes in ASP.NET form(C#). But in real time situation life is not that easy and we are faced with more than just text boxes. So this time I'll show how to clear some of the very comman controls on a ASP.NET form. C# private void ClearForm(Control parent) { foreach (Control ctl in parent.Controls) { if (ctl.Controls.Count > 0) { ResetFormControlValues(ctl); } else { switch(ctl.GetType().ToString()) { case "System.Web.UI.WebControls.TextBox": ((TextBox)ctl).Text = ""; break; case "System.Web.UI.WebControls.CheckBox": ((CheckBox)ctl).Checked = false; break; case "System.Web...

Reset Text Boxes in ASP.Net

Well a small tip on ASP.NET. Sometimes when creating some user input page we need to clear all the text boxes. One example of this can be a reset or cancel button. Here is a way to do this, iterating through the ASP.Net TextBox controls in a form. Just create a Reset type subroutine - in that routine, use the following code: in C# - it would be: Control myForm = Page.FindControl("Form1"); foreach (Control ctl in myForm.Controls) if(ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) ((TextBox)ctl).Text = ""; This will clear EVERYTHING from the textboxes - even if you had them pre-populated with data. Very neat!! Enjoy Programing.. Related Article: Reset Text Boxes in ASP.Net Part 2