How to dynamically generate a custom control ascx to pass values to ascx

Source: Internet
Author: User

I have the opportunity to see a problem posted on the Forum:



After the button is executed on the webpage, the user control that is dynamically loaded will be discarded when the sub-user control's button is executed. Therefore, we need to focus on the key points to be processed.
After the sub-user control in the same phase is dynamically loaded, its status also needs to be maintained. Otherwise, it will be discarded when it is passed to another sub-user control.
Another key point is the sub-user control, how to pass values to another user control.

After figuring out the key technical points, everything is easy.
On the website, create a webpage Default. aspx, two user controls UcA. ascx and UcB. ascx
In Default. aspx:



Go to UcA. aspx



Go to UcB. aspx



The html code of all web pages and user controls is complete.
UcB. aspx. cs needs to obtain a value. It is unclear where the value comes from, whether it is a webpage or another user control. Just like when I was a child, I asked my parents for money. We don't have to know whether the money was from their parents or borrowed from them. We just need to pay for it.
Insus. NET creates an interface that has a Set attribute.



The user control UcB. aspx. cs implements this interface:



Go to Default. aspx. cs to write the program:



ViewState is used to retain the Dynamically Loaded user control.
Go to UcA. ascx. cs:



The execution result of webpage running:



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.