简体   繁体   English

为什么我的链接按钮会执行完整的回发,尽管它是由更新面板触发的

[英]Why my link button does a full post back although it 's triggered with an update panel

I have the following case : 我有以下情况:

a link button which triggered through AsyncPostBackTrigger .but still does a full post back !! 一个通过AsyncPostBackTrigger触发的link button ,但仍然执行完整的回发!


<asp:LinkButton ID="lbtnShowNotes" runat="server" CssClass="blue" OnClick="lbtnShowNotes_Click"> <img src="images/document_notes.png"/>notes</asp:LinkButton>

  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Panel ID="pnlNotes" runat="server" Visible="false">
                        <asp:Label ID="lbl_title" runat="server" Text="الملاحظات"></asp:Label>
                        <asp:TextBox ID="txt_Coments" runat="server" Columns="70" Rows="5" TextMode="MultiLine"></asp:TextBox>
                        <asp:LinkButton ID="lbtnOkNotes" runat="server"><img src="images/tick.png" alt=""/></asp:LinkButton>
                        <asp:LinkButton ID="lbtnCancelNotes" runat="server" CausesValidation="False" OnClick="lbtnCancelNotes_Click"><img src="images/tick.png" alt=""/></asp:LinkButton>
                    </asp:Panel>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="lbtnShowNotes" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>

ClientIDMode Changes ClientIDMode更改

The ClientIDMode setting in ASP.NET 4 lets you specify how ASP.NET generates the id attribute for HTML elements. ASP.NET 4中的ClientIDMode设置使您可以指定ASP.NET如何生成HTML元素的id属性。 In previous versions of ASP.NET, the default behavior was equivalent to the AutoID setting of ClientIDMode. 在ASP.NET的早期版本中,默认行为等同于ClientIDMode的AutoID设置。 However, the default setting is now Predictable. 但是,默认设置现在是可预测的。

If you use Visual Studio 2010 to upgrade your application from ASP.NET 2.0 or ASP.NET 3.5, the tool automatically adds a setting to the Web.config file that preserves the behavior of earlier versions of the .NET Framework. 如果使用Visual Studio 2010从ASP.NET 2.0或ASP.NET 3.5升级应用程序,则该工具会自动将设置添加到Web.config文件中,以保留早期版本的.NET Framework的行为。 However, if you upgrade an application by changing the application pool in IIS to target the .NET Framework 4, ASP.NET uses the new mode by default. 但是,如果通过更改IIS中的应用程序池以.NET Framework 4为目标来升级应用程序,则ASP.NET默认情况下将使用新模式。 To disable the new client ID mode, add the following setting in the Web.config file: 若要禁用新的客户端ID模式,请在Web.config文件中添加以下设置:

<pages ClientIDMode="AutoID" />

or add ClientIDMode="AutoID" in your page directive. 或在页面指令中添加ClientIDMode =“ AutoID”。

http://www.asp.net/whitepapers/aspnet4/breaking-changes http://www.asp.net/whitepapers/aspnet4/breaking-changes

LinkButton in ListView in UpdatePanel causes full postback UpdatePanel中ListView中的LinkBut​​ton导致完全回发

在页面指令中添加ClientIDMode="AutoID"解决了我的问题。

Change the UpdatePanel 's UpdateMode Property to "Conditional". UpdatePanelUpdateMode属性更改为“ Conditional”。

<asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">

The UpdatePanel is updated if the UpdateMode property is set to Conditional , and one of the following conditions occurs: 如果UpdateMode属性设置为Conditional ,则会更新UpdatePanel ,并且发生以下情况之一:

  • You call the Update method of the UpdatePanel control explicitly. 您显式调用UpdatePanel控件的Update方法。
  • The postback is caused by a control that is defined as a trigger by using the Triggers property of the UpdatePanel control. 回发是由使用 UpdatePanel控件的Triggers属性定义为触发器的控件引起的。 In this scenario, the control explicitly triggers an update of the panel content. 在这种情况下,该控件显式触发面板内容的更新。 The control can be either inside or outside the UpdatePanel control that defines the trigger. 该控件可以在定义触发器的UpdatePanel控件内部或外部
  • ... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM