Experiences in Asp.net development [events delegated to pages for dynamically loaded user controls are invalid]

Source: Internet
Author: User

When developing a complex page, the page is often used. the loadcontrol method obtains the user control and adds it to the Web Container Control. Usually, it is a placeholder or panel.
(In. In dottext, placeholder is inherited from panel)

During development, I defined an event in the user control and tried to let the page handle the event.
At this time, I found a problem. Originally, I triggered a button in a user control. This button event was defined on the page for processing, but it was not reflected at this time. This button event can be triggered only once.

Because every time I load the page, I will determine which user control to load based on the relevant parameters. The registered event is invalid at this time.

If I do not load it dynamically, it is no problem that the user control uses event Delegate to handle it on the page.

Therefore, I suggest that if you can determine the user control, you can use event Delegate and hand in page processing.
If the user control is dynamically loaded, it is best not to use event delegation and hand in page processing (this message transmission mechanism ).

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.