Traverse all textbox on the page and assign the value to string. Empty (ASP. NET and winform)

Source: Internet
Author: User

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 
  
Related Article

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.