How to Empty Controls in ASP.NET
////// Empty Controls in the page.
///
private void EmptyControl()
{
foreach (Control ctrl in this.Form.Controls)
{
if (ctrl is ContentPlaceHolder)
{
ContentPlaceHolder chp = ((System.Web.UI.WebControls.ContentPlaceHolder)ctrl);
foreach (Control ctrl2 in chp.Controls)
{
if (ctrl2 is TextBox)
{
TextBox tb = ((System.Web.UI.WebControls.TextBox)ctrl2);
tb.Text = "";
}
if (ctrl2 is DropDownList)
{
DropDownList dl = ((System.Web.UI.WebControls.DropDownList)ctrl2);
dl.SelectedIndex = 0;
}
if (ctrl2 is CheckBoxList)
{
CheckBoxList dl = ((System.Web.UI.WebControls.CheckBoxList)ctrl2);
dl.ClearSelection();
}
if (ctrl2 is CheckBox)
{
CheckBox dl = ((System.Web.UI.WebControls.CheckBox)ctrl2);
dl.Checked = false;
}
}
}
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.