What is AsyncPostBackTrigger Class?

3

How should I use and what does this type of class?

    
asked by anonymous 26.03.2017 / 04:25

1 answer

2

Defines a control and an optional event of the control as a control trigger for postback assíncrono which causes the UpdatePanel control to be updated. Reference Microsoft Developer Network - AsyncPostBackTrigger Class .

Basically, when you use UpdatePanel , the contained controls it has its information updated without giving a refresh on the page, but, there is a technique that when declaring a AsyncPostBackTrigger of some control outside the UpdatePanel make this control have the same behavior as the UpdatePanel .

A example would be the declaration of this form:

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:Button ID="BtnDateTimeNowUpdate" 
                runat="server" 
                Text="Atualizar" 
                OnClick="BtnDateTimeNowUpdate_Click" />
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="BtnDateTimeNowUpdate" />
            </Triggers>
            <ContentTemplate>
                <asp:Label ID="LblDateTimeNow" runat="server" Text=""></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>

In this simple code, note that the BtnDateTimeNowUpdate button is out of the UpdatePanel , but does have the same behavior as if it were inside it by the simple configuration found in UpdatePanel :

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="BtnDateTimeNowUpdate" />
</Triggers>

If this setting was not this way, this button would give a refresh on the whole page which is the normal behavior for WebForm .

Can be used when a control outside the UpdatePanel , you must interact with the controls within the UpdatePanel .

27.03.2017 / 16:27