Friday, February 5, 2010

What is and AsyncPostBackTrigger object?

If we call any events based on controls outside of the UpdatePanel, the whole page is reloaded unless we take certain steps to prevent that from happening.
Why place controls outside of the UpdatePanel container if they are to be used for working with events inside the UpdatePanel container. We may be working with an existing site that originally did not have Ajax functionality. Instead of moving the different controls inside the UpdatePanel container, we just want their events to have an effect on the UpdatePanel controls.
Fortunately, the solution for using Ajax with control events outside the UpdatePanel container is relatively simple. We can use the <Triggers> tag and the AsyncPostBackTrigger object to listen to the events of controls of the UpdatePanel container. The following shows the relevant code structure:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ControlName"
EventName="EventName" />
</Triggers>
By default, the trigger container goes inside the UpdatePanel container but outside of the <ContentTemplate> container.
In this context the EventName refers to the name of the event launched by the control, and not to the target function in the C# code. For example, a Button control may have a “Click” event, so the assignment
EventName="Click"
Would mean that from inside the UpdatePanel container, the control outside the container is set up as a non - Ajax control. Then within UpdatePanel container, the triggers just listen for the appropriate event from the named control; only the updated material, and not the whole page, is updated.

No comments:

Post a Comment