How to empty all TextBoxes of the page at one shot?

SheoNarayan
Posted by SheoNarayan under ASP.NET category on | Views : 5070
Write following function in the common class.


public class MyClass
{
public static void ResetTextBoxes(Control oControl)
{
foreach (Control c in oControl.Controls)
{
if (c is TextBox)
{
TextBox t = (TextBox)c.FindControl(c.ID);
t.Text = string.Empty;
}
if (c.HasControls())
{
ResetTextBoxes(c);
}
}
}//ResetTextBoxes
}


Call the above function like this

MyClass. ResetTextBoxes(this);


You should ensure that you are using following namespace in the class file where you are writing this function
using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;

Comments or Responses

Posted by: Poster on: 10/16/2008 Level:Starter | Status: [Member]
This one is really cool and small and very useful in all projects but I guess it will only reset the value of TextBox not dropdown and other controls.

Login to post response