Use findcontrol in the master page (when multiple layers of nested masters are included)

Source: Internet
Author: User

Obtain the control in a multi-layer master:

Contentplaceholder holder = (Contentplaceholder) Master. Master. findcontrol ( " Contentplaceholder1 " );
Contentplaceholder holder2
= (Contentplaceholder) Holder. findcontrol ( " Contentplaceholder2 " );
Textbox txt_test
= (Textbox) holder2.findcontrol ( " Test " );

 

Call the control of the user control itself:

(Label) This . Findcontrol ( " Label1 " ). Text =   " 123 " ;

Note that page. findcontrol cannot be used to locate the issue. Use this

Call the control on the user control on the host interface:

System. Web. UI. usercontrol UC = (System. Web. UI. usercontrol) page. findcontrol ( " Webusercontrol1 " );
(Label) UC. findcontrol (
" Label1 " ). Text =   " 123 " ;

 

Call the controls on the user control on the host interface containing the master:

Contentplaceholder holder = (Contentplaceholder) page. master. findcontrol ( " Contentplaceholder1 " );
System. Web. UI. usercontrol UC
= (System. Web. UI. usercontrol) Holder. findcontrol ( " Webusercontrol1 " );
(Label) UC. findcontrol (
" Label1 " ). Text =   " 123 "

 

Set the value in user B control from user a control:

System. Web. UI. usercontrol UC = (System. Web. UI. usercontrol) page. findcontrol ( " Webusercontrol1 " );
(Label) UC. findcontrol (
" Label1 " ). Text =   " 123 " ;

 

Overall feeling: It is troublesome to use findcontrol on pages where a master or even a master is embedded. I don't know if there is any good solution.

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.