Asp.net user control event thrown back

Source: Internet
Author: User

Requirement: After the data is saved in the user control, refresh the data list on the host page and asynchronously refresh the data list.

Solution: Click the Save button in the user control to refresh List A on the host page. First, we need to use updatepanel to package list, then, you only need to find a way to refresh the updatepanel after clicking the Save button. However, on the host page, we cannot directly mount the updatepanel triggle with the Save button in the user, even if it can be mounted, however, we still need to use the Save button to update the host page, which is very troublesome. However, as long as the user control can throw an event, we only need to implement this event on the host page to complete the refresh, in addition, updatepanel can be directly linked to the event that the user control runs. As long as this event is triggered by the Save button. Our problem is solved.

How to Create a throw eventCodeAs follows:

 

Code

// Code in the control

Public   Delegate   Void Clickeventhandler ( Object Sender, eventargs E );

Public EventClickeventhandler click;

protected void btnsave_click ( Object sender, eventargs e)
{< br> /// here, You can implement your own business and store information in
If (Click ! = null )
{< br> click ( This , e); /// throw this event and execute the event implemented on the host page
}< BR >}

// host page
This . uccompanyinfor. click += New pages_companyprofile_companyinforamtion.clickeventhandler (uccompanyinfor_click );

Protected VoidUccompanyinfor_click (ObjectSender, eventargs E)
{
Bindleftdatasource ();//Refresh the host page list
}

//

 

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.