c# – What is AsyncPostBackTrigger Class?

Question:

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

Answer:

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

Basically, when using UpdatePanel , the controls contained therein has your updated information without taking a refresh on the page, but there is a technique to declare a AsyncPostBackTrigger some control outside the UpdatePanel make this control have the same behavior of those within the UpdatePanel .

An example would be the statement like this:

<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, notice that the BtnDateTimeNowUpdate button is outside the UpdatePanel , but has the same behavior as if it were inside it by the simple configuration present in the UpdatePanel :

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

if this setting wasn't like this, this button would refresh entire page which is normal behavior for WebForm .

It can be used, when a control outside the UpdatePanel , has to interact with the controls inside the UpdatePanel .

References

Scroll to Top