Set all controls on the page to read-only.

Source: Internet
Author: User

/// <Summary> <br/> /// set all the controls on the current page to read-only <br/> /// </Summary> <br/> // <Param name = "page"> </param> <br/> Public static void setcontrolreadonly (page) <br/>{</P> <p> foreach (control CTRL in page. controls) <br/>{< br/> setcontrolreadonly (CTRL ); </P> <p >}< br/>}</P> <p> // recursive call. Set the read-only control. <Br/> Public static void setcontrolreadonly (control CTR) <br/> {<br/> If (CTR is textbox) <br/>{< br/> textbox txtcontrol = (textbox) CTR; <br/> txtcontrol. readonly = true; <br/> txtcontrol. enabled = false; </P> <p >}< br/> else if (CTR is radiobutton) <br/>{< br/> radiobutton BTN = (radiobutton) CTR; <br/> BTN. enabled = false; </P> <p >}< br/> else if (CTR is radiobuttonlist) <br/>{< br/> radiobuttonlist BTN = (radiobuttonlist) CTR; <br/> BTN. enabled = false; <br/>}</P> <p> else if (CTR is checkbox) <br/>{< br/> checkbox cb = (checkbox) CTR; <br/> CB. enabled = false; <br/>}< br/> else if (CTR is dropdownlist) <br/>{< br/> dropdownlist list = (dropdownlist) CTR; <br/> list. enabled = false; <br/>}</P> <p> else if (CTR is htmltextarea) <br/>{< br/> htmltextarea cb = (htmltextarea) CTR; <br/> CB. attributes. add ("readonly", ""); <br/> CB. disabled = true; <br/>}< br/> else if (CTR is htmlselect) <br/>{< br/> htmlselect RB = (htmlselect) CTR; <br/> RB. disabled = true; <br/>}</P> <p> else if (CTR is htmlinputcheckbox) <br/>{< br/> htmlinputcheckbox RB = (htmlinputcheckbox) CTR; <br/> RB. disabled = true; <br/>}< br/> else if (CTR is htmlinputradiobutton) <br/>{< br/> htmlinputradiobutton RB = (htmlinputradiobutton) CTR; <br/> RB. disabled = true; <br/>}< br/> else if (CTR is htmlinputtext) <br/>{< br/> htmlinputcontrol input = (htmlinputcontrol) CTR; <br/> input. attributes. add ("readonly", ""); <br/> input. disabled = true; <br/>}< br/> else <br/> foreach (control ctr1 in Ctr. controls) <br/>{< br/> setcontrolreadonly (ctr1); <br/>}< br/>}

Because it is a recursive call, you can pass in the current page. The method will find all the controls on the page.

 

/// <Summary> <br/> // cancel the read-only attribute <br/> /// </Summary> <br/> /// <Param name = "Page "> page to operate, generally, this </param> <br/> // <Param name = "controlid"> Control ID </param> <br/> Public static void removereadonlybyid (page, string controlid) <br/>{</P> <p> Control CTR = page. findcontrol (controlid); <br/> If (CTR is textbox) <br/>{< br/> textbox txtcontrol = (textbox) CTR; <br/> txtcontrol. readonly = false; <br/> txtcontrol. enabled = true; </P> <p >}< br/> else if (CTR is radiobutton) <br/>{< br/> radiobutton BTN = (radiobutton) CTR; <br/> BTN. enabled = true; </P> <p >}</P> <p> else if (CTR is checkbox) <br/>{< br/> checkbox cb = (checkbox) CTR; <br/> CB. enabled = true; <br/>}< br/> else if (CTR is dropdownlist) <br/>{< br/> dropdownlist list = (dropdownlist) CTR; <br/> list. enabled = true; <br/>}</P> <p> else if (CTR is htmltextarea) <br/>{< br/> htmltextarea cb = (htmltextarea) CTR; <br/> CB. attributes. remove ("readonly"); <br/> CB. disabled = false; <br/>}< br/> else if (CTR is htmlselect) <br/>{< br/> htmlselect RB = (htmlselect) CTR; <br/> RB. disabled = false; </P> <p >}</P> <p> else if (CTR is htmlinputcheckbox) <br/>{< br/> htmlinputcheckbox RB = (htmlinputcheckbox) CTR; <br/> RB. disabled = false; <br/>}< br/> else if (CTR is htmlinputradiobutton) <br/>{< br/> htmlinputradiobutton RB = (htmlinputradiobutton) CTR; <br/> RB. disabled = false; <br/>}< br/> else if (CTR is htmlinputtext) <br/>{< br/> htmlinputcontrol input = (htmlinputcontrol) CTR; <br/> input. attributes. remove ("readonly"); <br/> input. disabled = false; <br/>}</P> <p>}

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.