C# UpdatePanel 上的 AsyncPostBackTrigger 和 PostBackTrigger 之间的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15330089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:26:36  来源:igfitidea点击:

Difference between AsyncPostBackTrigger and PostBackTrigger on UpdatePanel?

c#asp.net

提问by Christian Mark

I have a GridView(ucLAD) in my UpdatePanel(upnlListing). Inside my ucLADI have a checkbox and an action for rowClicked:

我的GridView(upnlListing) 中有一个UpdatePanel(ucLAD)。在我的内部,我ucLAD有一个复选框和一个操作rowClicked

<asp:UpdatePanel ID="upnlListing" runat="server" >
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ucLAD"/>
        <%-- <asp:PostBackTrigger ControlID="ucLAD"/> --%>
     </Triggers>
     <ContentTemplate>
        <asp:Panel ID="pnlRequest" runat="server" style="margin-top:15px; height: auto;">
             <ucgv:BaseGrid runat="server" ID="ucLAD"/>
        </asp:Panel>

     </ContentTemplate>  
</asp:UpdatePanel>

When I use the PostBackTriggerthe action performed would be the rowClickedsame thing happen when I check the checkbox but when I use the AsyncPostBackTrigger, I can check the checkboxes but when I click the row, the action for rowClickeddon't trigger. How can I fix this?

当我使用执行PostBackTrigger的操作rowClicked时,当我选中复选框时会发生同样的事情,但是当我使用 时AsyncPostBackTrigger,我可以选中复选框,但是当我单击该行时,rowClicked不会触发该操作。我怎样才能解决这个问题?

采纳答案by ????

As describe in on of the SO question

正如在 SO 问题中所描述的

What is the difference between AsyncPostBackTrigger & PostBackTrigger?

AsyncPostBackTrigger 和 PostBackTrigger 有什么区别?

Controls inside an UpdatePanel by default cause a partial page update, controls outside cause a postback, using these triggers it is possible to change this behaviour as required.

默认情况下,UpdatePanel 内部的控件会导致部分页面更新,外部的控件会导致回发,使用这些触发器可以根据需要更改此行为。

From http://seminaarit.codezone.fi/video/devdays-2007/track1/2/2-ASP-dotNET_AJAX_Extensions.ppt

来自http://seminaarit.codezone.fi/video/devdays-2007/track1/2/2-ASP-dotNET_AJAX_Extensions.ppt

AsyncPostBackTrigger

AsyncPostBackTrigger

Converts postbacks into async callbacks Typically used to trigger updates when controls outside an UpdatePanel post back If ChildrenAsTriggers="false", can be used to specify which controls inside UpdatePanel should call back rather than post back

将回发转换为异步回调 通常用于在 UpdatePanel 之外的控件回发时触发更新 如果 ChildrenAsTriggers="false",可用于指定 UpdatePanel 内的哪些控件应该回调而不是回发

PostBackTrigger

回传触发器

Lets controls inside UpdatePanel post back Typically used to allow certain controls to post back when ChildrenAsTriggers="true

让 UpdatePanel 内的控件回发 通常用于在 ChildrenAsTriggers="true 时允许某些控件回发

回答by priya uthaya

Theoretical explain for AsyncPostBackTrigger and PostBackTrigger above is absolutely Correct. Here I gave You example for those two:

上面对 AsyncPostBackTrigger 和 PostBackTrigger 的理论解释是完全正确的。在这里,我为您提供了这两个示例:

<td style="padding-left: 8px;">
     <asp:UpdatePanel  runat="server" ChildrenAsTriggers="false" UpdateMode="conditional">
         <ContentTemplate>
         <asp:RadioButton ID="RBtn_InventoryPriceWithPurchase" Text="Inventory Price With Purchase" GroupName="ReportAnalysis" runat="server" AutoPostBack="True" OnCheckedChanged="RBtn_InventoryPriceWithPurchase_CheckedChanged"/>
         </ContentTemplate>
          <Triggers>
           <asp:AsyncPostBackTrigger ControlID="RBtn_InventoryPriceWithPurchase"EventName="CheckedChanged"/>
          </Triggers>
          </asp:UpdatePanel>
</td>

<td style="padding-left: 8px;">
    <asp:UpdatePanel runat="server" ChildrenAsTriggers="True" UpdateMode="Always">
     <ContentTemplate>
  <asp:RadioButton ID="RBtn_MerchandisingReport" Text="Merchandising Report" GroupName="ReportAnalysis" runat="server" AutoPostBack="True" OnCheckedChanged="RBtn_MerchandisingReport_CheckedChanged" />
  </ContentTemplate>
  <Triggers>
 <asp:PostBackTrigger ControlID="RBtn_MerchandisingReport"/>
 /Triggers>
 </asp:UpdatePanel>