How to traverse all the controls on a specified page under ASP.net
Source: Internet
Author: User
Asp.net| Traversal | controls | How the page traverses all controls on the specified page under ASP.net
Preface: The purpose of writing it down is to feel that this code will help some friends!
#region empty all control contents on the specified page, public static void Clearallcontent ()
<summary>
Clears all control contents on the specified page, including textbox,checkbox,checkboxlist,radiobutton,radiobuttonlist. But not clear.
In addition to listbox,dropdownlist, because such a control value is still available for the current page, these controls are typically saved in dictionary data.
Author:kevin
Date: 2004-12-02
</summary>
<param name= "page" > specified page </param>
public static void Clearallcontent (System.Web.UI.Control page)
{
int npagecontrols = page. Controls.Count;
for (int i = 0; i < npagecontrols; i++)
{
foreach (System.Web.UI.Control control in page. Controls[i]. Controls)
{
if (control. Hascontrols ())
{
Clearalltext (Control);
}
Else
{
If (Control is TextBox)
(Control as TextBox). Text = "";
If (Control is CheckBox)
(Control as CheckBox). Checked = false;
If (Control is RadioButtonList)
(Control as RadioButtonList). SelectedIndex =-1;
If (Control is RadioButton)
(Control as RadioButton). Checked = false;
If (Control is CheckBoxList)
{
foreach (ListItem item in (Control as CheckBoxList). Items)
{
Item. Selected = false;
}
}
}//if.. Else
}//foreach
}//for
}
#endregion
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.