Thursday, 5 April 2012

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


using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;
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 as: MyClass.ResetTextBoxes(this);

No comments:

Post a Comment