Stan
Stan

Reputation: 411

ASP.NET Update Panel postback only by trigger

Is it possible to have the control inside the update panel not to cause a postback and update the control only by a trigger. I have tried adding the tag "Triggers" but control is still updating after I do something on it.

<td>
    <asp:UpdatePanel ID="UpdatePanel7" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <uc1:CBP runat="server" ID="C1" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="C2" />
        </Triggers>
    </asp:UpdatePanel>
</td>

Upvotes: 0

Views: 2064

Answers (2)

JaggenSWE
JaggenSWE

Reputation: 2094

It all depends on how you've set it up. If you have a Control that resides outside the update panels, that Control will do a postback to the entire page.

Example:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <asp:ScriptManager ID="smDefault" runat="server" />
    <asp:UpdatePanel ID="upnlTime" runat="server" RenderMode="Block" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Label ID="lblTime" runat="server" />
            <br />
            <asp:Button ID="btnInsideUpdate" runat="server" Text="Update from Inside" OnClick="btnInsideUpdate_Click" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnInsideUpdate" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="upnlOutside" runat="server" RenderMode="Block" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="btnOutsideUpdate" runat="server" Text="Update from outside" OnClick="btnOutsideUpdate_Click" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnOutsideUpdate" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    <br />
    <asp:Button ID="btnUpdatePage" runat="server" Text="Update Page" OnClick="btnUpdatePage_Click" />
</div>
</form>

The btnInsideUpdate will update the contents of the updatepanel, as will the btnUpdatePage, however, the btnOutsideUpdate won't since that resides in Another update panel.

Upvotes: 0

Andrei
Andrei

Reputation: 56688

You also need to make sure ChildrenAsTriggers property is set to false, otherwise your update panel can be triggered by its children as well as by defined triggers. Default of this property is true, which explains the behavior:

<asp:UpdatePanel ID="UpdatePanel7" runat="server"
                 UpdateMode="Conditional"
                 ChildrenAsTriggers="false">

This can also be found in the docs:

If the UpdateMode property is set to Conditional, and one of the following conditions occurs: ... The ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. A child control of a nested UpdatePanel control does not cause an update to the outer UpdatePanel control unless it is explicitly defined as a trigger.

Upvotes: 1

Related Questions