khalid13
khalid13

Reputation: 2837

Preventing UpdatePanel partial postbacks

I have an UpdatePanel on a pretty slow page. Its UpdatePanel is set to update conditionally. The problem I'm facing is that the UpdatePanel does a partial postback immediately on being rendered clientside. My questions are:

  1. Is it possible to prevent that first partial postback from happening?
  2. Is that even good practice? Why or why not?

Thanks for your help.

Markup:

        <asp:UpdatePanel UpdateMode="Conditional"  ChildrenAsTriggers="false" runat="server" ID="updatePnlValidationErrors">
            <ContentTemplate>
                <span runat="server" id="validationErrors" class="error"></span>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger EventName="Click" ControlID="btnCompletePurchase" />
                <asp:AsyncPostBackTrigger EventName="Checkout_Click" ControlID="checkoutBox" />
            </Triggers>
        </asp:UpdatePanel>

There is no code directly touching the UpdatePanel.

Upvotes: 1

Views: 1328

Answers (1)

Ali
Ali

Reputation: 2592

OK, your asyncpostbacktrigger in your code are not pointing to the right controls I guess, you may have eliminated them only for the demo purposes but they are critical for our test. here is my complete simulation of your code and its results at the end.

I have added two missing associated controls for your AsyncPostBackTriggers outside your update panel;

 <asp:Button ID="btnCompletePurchase" runat="server" Text="Button"
             OnClick="btnCompletePurchase_Click" />
 <asp:CheckBox ID="checkoutBox" runat="server" 
               OnCheckedChanged="checkoutBox_CheckedChanged" />

and your code will look like the code below:

 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

 <asp:Button ID="btnCompletePurchase" runat="server" Text="Button"
             OnClick="btnCompletePurchase_Click" />
 <asp:CheckBox ID="checkoutBox" runat="server" 
               OnCheckedChanged="checkoutBox_CheckedChanged" />
 <asp:UpdatePanel UpdateMode="Conditional"  ChildrenAsTriggers="false" 
                  runat="server" ID="updatePnlValidationErrors">
     <ContentTemplate>
        <span runat="server" id="validationErrors" class="error"></span>
     </ContentTemplate>
     <Triggers>
        <asp:AsyncPostBackTrigger EventName="Click" 
                                      ControlID="btnCompletePurchase" />
        <asp:AsyncPostBackTrigger EventName="CheckedChanged" 
                                      ControlID="checkoutBox" />
     </Triggers>
 </asp:UpdatePanel>

and here is the break point result on first time Page_Load event:

enter image description here

so you could copy and paste this code to check the result at your end as well.

Upvotes: 1

Related Questions