简体   繁体   English

UpdatePanel AsyncPostBackTrigger会回发

[英]UpdatePanel AsyncPostBackTrigger does Postback

I've below design code containing updatepanel to the gridview and buttons as shown below - 我下面的design code包含对gridviewbuttons updatepanel ,如下所示-

<asp:ScriptManager ID="scrptmanager" runat="server"></asp:ScriptManager>
    <div>
        <asp:HiddenField ID="hdnSortValue" runat="server" />
    </div>
    <div class="current-btns" style="float: left !important;">
        <div id="divFitnessSortBy" runat="server" class="fit-sort">
            <table>
                <tr>
                    <td>
                        <b>Sort by :</b>
                    </td>
                    <td>
                        <asp:Button ID="btnMostRecent" Text="Most Recent" class="button action sortcomments"
                            runat="server" OnCommand="btnMostRecent_Click" CommandArgument="date" />
                    </td>
                    <td>
                        <asp:Button ID="btnMostViewed" Text="Most Viewed" class="Comments" runat="server"
                            OnCommand="btnMostViewed_Click" CommandArgument="views" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="hr">
    </div>
    <div class="BlogsPostHolderDiv" id="divPagination">
    <asp:UpdatePanel ID="updtpanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:GridView ID="gvBlogsPost" runat="server" DataKeyNames="PostID" AutoGenerateColumns="False"
            AllowPaging="false" Width="100%" OnRowDataBound="gvBlogsPost_Bound" GridLines="None">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <div class="current-articles">
                            <div class="current-thumb">
                                <a id="lnkThumbnail" runat="server" rel="nofollow">
                                    <asp:Image ID="imgThumbnail" runat="server" Height="135px" Width="186px" />
                                </a>
                            </div>
                            <div class="current-list">
                                <h2>
                                    <a id="lnkArticle" runat="server">
                                        <%# DataBinder.Eval(Container.DataItem, "Subject")%></a>
                                </h2>
                                <div class="views-comments">
                                    <h5>
                                        <asp:Label runat="server" ID="lblNewsletterDate" ForeColor="#808080"><%# DataBinder.Eval(Container.DataItem, "PostDate")%></asp:Label>
                                        <span class="gray">|</span> <span id="spnViews" runat="server"><span>
                                            <%#Convert.ToInt64(DataBinder.Eval(Container.DataItem, "TotalViews")).ToString("#,#")%>
                                            Views </span></span>
                                    </h5>
                                </div>
                                <asp:Label ID="lblShortDescription" runat="server"><%#DataBinder.Eval (Container.DataItem, "Body")%> </asp:Label>
                            </div>
                            <div class="clear">
                            </div>
                        </div>
                        <div class="hr">
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>

        </asp:GridView>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnMostRecent" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="btnMostViewed" EventName="Click" />
        </Triggers>
        </asp:UpdatePanel>            
    <input type="hidden" id="hdnLastArticle" value="10" />

When i click on btnMostRecent or btnMostViewed the page does postback which should not be the case...am i missing something here? 当我click btnMostRecentbtnMostViewed ,页面会postback ,这不应该是这种情况……我在这里缺少什么吗?

Expected - When i click on any of the given button only gvBlogsPost gridview should be updated without the whole page postback 预期 -当我click任何给定的buttongvBlogsPost gridview应该被更新,而没有whole page postback

Help and thanks in advance...! 提前帮助和感谢...!

It looks the only thing you have to do is make sure the triggers are in the same naming container. 看起来您唯一要做的就是确保触发器位于相同的命名容器中。

According to MSDN : 根据MSDN

The control that the AsyncPostBackTrigger control references must be in the same naming container as the update panel for which it is a trigger. AsyncPostBackTrigger控件引用的控件必须与作为触发器的更新面板位于同一命名容器中。 Triggers that are based on controls in other naming containers are not supported. 不支持基于其他命名容器中的控件的触发器。

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

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