How to traverse all the controls on a specified page under ASP.net

Source: Internet
Author: User

#region empty all control contents on the specified page, the public static void Clearallcontent ()//////clears all control contents on the specified page, including Textbox,checkbox,checkboxlist,ra 
Diobutton,radiobuttonlist. But not clear///in addition to such as listbox,dropdownlist, because such a control value for the current page can also be used, generally these controls are saved dictionary data. 
    Author:kevin///Date: 2004-12-02//////specified page 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's TextBox) (Control as TextBox).
                
                Text = ""; if (control's CheckBox) (Control as CheckBox).
                
                Checked = false; If (Control are RadioButtonList) (control as RadioButtonList).
                
  SelectedIndex =-1;              If (Control are RadioButton) (control as RadioButton).
                
                Checked = false;  If (control are CheckBoxList) {foreach (ListItem item in (Control as CheckBoxList) ). Items) {Item.
                    Selected = false; The}}}}} #endregi

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.