Clear Controls In Asp.Net on Button Click after Submitting Data

Dotnet4ashu
Posted by Dotnet4ashu under ASP.NET category on | Points: 40 | Views : 3751
hello Experts

Every developer need Clear Control Class After Submitted Data Earlier some developer use
like this,
textid.text="";

But This is new one........... EveryOne can use this just open class in appcode.

public int cleartextbox(Control primary)
{
foreach (Control _ChildControl in primary.Controls)
{
if ((_ChildControl.Controls.Count > 0))
{
cleartextbox (_ChildControl);

}
else
{
if (_ChildControl is TextBox)
{
((TextBox)_ChildControl).Text = string.Empty;
}
if (_ChildControl is DropDownList)
{
((DropDownList)_ChildControl).Text = string.Empty;
}
if (_ChildControl is RadioButtonList)
{
((RadioButtonList)_ChildControl).Text = string.Empty;
}
if (_ChildControl is CheckBoxList)
{
((CheckBoxList)_ChildControl).Text = string.Empty;
}
if (_ChildControl is CheckBox)
{
((CheckBox)_ChildControl).Text = string.Empty;
}
}
}

return 0;
}


Call it on Aspx.cs

private int cleartext()
{ //call the class that you have created in appcode and create the object
clearclass obj=new clearclass();
retrun obj.clearControls(this);
}

Comments or Responses

Posted by: T.Saravanan on: 2/21/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Nice info.

For looking good, Kindly post your code inside the code tag.

Login to post response