1. Traverse Form Controls
1. the common page traverses the Textbox Control clearing method. Other controls are similar to the foreach (control C in this. controls) {If (C is textbox) {textbox TB = (textbox) C; TB. TEXT = string. empty;} // or foreach (control Col in this. controls) {If (Col. getType (). name. equals ("textbox") {(textbox) COL ). TEXT = string. empty ;}}
Ii. traverse the Asp.net page
// The foreach (system. web. UI. control txtobj in this. page. controls) {If (txtobj. getType (). name. equals ("textbox") {// (textbox) txtobj ). TEXT = string. empty; // This is the first method to assign values. The second method is textbox TB = new Textbox (); TB = (textbox) This. findcontrol (txtobj. ID); TB. TEXT = string. empty ;}}
Includes dashboard page
// Use the page of the master page to traverse the Textbox Control. Other controls are similar to foreach (control CP in page. controls) {foreach (system. web. UI. control CT in CP. controls) {If (CT is htmlform) {foreach (control con in CT. controls) {foreach (control C in con. controls) {If (C is textbox) {(C as textbox ). TEXT = string. empty ;}}}}}}
3. Clear control content
// clear all the controls on the specified page // public static void clearallcontent () // clear all the controls on the specified page // includes Textbox, checkbox, checkboxlist, radiobutton, and radiobuttonlist. But it is not clear // except ListBox and dropdownlist, because such control values can be used for the current page. Generally, these controls contain stored Dictionary data. // specified page Public static void clearallcontent (system. web. UI. control page) {int npagecontrols = page. controls. count; For (INT I = 0; I