how to clear all textboxes,drop down list at a time in a click event using for each ?

Posted by aswinialuri-19361 under ASP.NET category on | Points: 40 | Views : 1202
using for each control you can clear all textboxes at a time
why we are choosing for each here is in a wb page there is 80 text boxes then what we have to do
 instead of textbox1.text=""; 
using for each it make an easy
code in .aspx.cs page
protected void btn_new_click(object sender, EventArgs e)


private void clear(ControlCollection ctrl)
foreach (Control ctrl1 in ctrl)
if (ctrl1 is TextBox)
((TextBox)ctrl1).Text = string.Empty;
else if (ctrl1 is DropDownList)

by using this we can achieve
and using this concept we can reduce the programmer burden

Comments or Responses

Login to post response