0

我有一个包含在更新面板中的转发器,并且在转发器之外有按钮和下拉列表。我不希望每次单击按钮或更改下拉列表中的某些内容时都加载页面。我在下面有我的代码。我有 2 个无法解决的问题:

1)即使我使用更新面板并触发(btn15MIN_Click),控件也会进入 Page_Load 事件,所以我想在编写更新面板代码时我做错了什么。

2)更改下拉列表值后需要很长时间才能更新中继器。

<div class="MainGrid">
        <asp:Timer ID="RefreshTimer" runat="server" OnTick="RefreshTimer_Tick" Enabled="True">
        </asp:Timer>
        <div>
            <table width="100%" cellpadding="5">
                <tr>
                    <td>
                        <div>
                            <asp:Label ID="lblEndDate" runat="server" Text="LastUpdatedDate:" Font-Bold="true"
                                CssClass="label" ForeColor="Black"></asp:Label>
                            <asp:Label ID="lblEndDateText" runat="server" CssClass="label" ForeColor="Black"></asp:Label>
                        </div>
                        <div>
                            <asp:Label ID="lblRefresh" runat="server" Text="Refresh Interval:" CssClass="label"
                                ForeColor="Black"></asp:Label>&nbsp&nbsp&nbsp
                            <asp:LinkButton ID="btn15MIN" runat="server" OnClick="btn15MIN_Click" Text="15MIN">
                            </asp:LinkButton>&nbsp
                            <asp:LinkButton ID="btn10MIN" runat="server" OnClick="btn10MIN_Click" Text="10MIN">
                            </asp:LinkButton>&nbsp
                            <asp:LinkButton ID="btn5MIN" runat="server" OnClick="btn5MIN_Click" Text="5MIN">
                            </asp:LinkButton>&nbsp
                            <asp:LinkButton ID="btn60SEC" runat="server" OnClick="btn60SEC_Click" Text="60SEC">
                            </asp:LinkButton>&nbsp
                            <asp:LinkButton ID="btn30SEC" runat="server" OnClick="btn30SEC_Click" Text="30SEC">
                            </asp:LinkButton>&nbsp
                            <asp:LinkButton ID="btnOFF" runat="server" OnClick="btnOFF_Click" Text="btnOFF">
                            </asp:LinkButton>
                        </div>
                        <asp:Panel ID="Panel2" runat="server">
                            <asp:Label ID="lblResultsDuration" runat="server" CssClass="label" ForeColor="Black">View Results since the last </asp:Label>
                            <asp:DropDownList ID="ddlDuration" OnSelectedIndexChanged="ddlDuration_SelectedIndexChanged"
                                runat="server">
                                <asp:ListItem Text="2" Value="2"></asp:ListItem>
                                <asp:ListItem Text="4" Value="4"></asp:ListItem>
                                <asp:ListItem Text="6" Value="6"></asp:ListItem>
                                <asp:ListItem Text="8" Value="8"></asp:ListItem>
                                <asp:ListItem Text="24" Value="24"></asp:ListItem>
                                <asp:ListItem Text="48" Value="48"></asp:ListItem>
                            </asp:DropDownList>
                            <asp:Label ID="lblResultsDuration1" runat="server" CssClass="label">  Hours </asp:Label>
                        </asp:Panel>
                        <asp:UpdatePanel ID="MainGridUpdatePanel" runat="server">
                            <Triggers>
                                <asp:PostBackTrigger ControlID="btn15MIN"  />
                            </Triggers>
                            <ContentTemplate>
                                <asp:Panel ID="pnlMonitorSummary" runat="server">
                                    <ul id="monitorGallery" class="gallery ui-helper-reset ui-helper-clearfix" style="margin-top: 5px;">
                                        <asp:Repeater ID="rptMonitorSummary" runat="server" OnItemDataBound="rptMonitorSummary_OnItemDataBound">
                                            <ItemTemplate>
                                                <li class="ui-widget-content ui-corner-tr">
                                                    <h5 class="ui-widget-header">
                                                        <%# Eval("Name").ToString().Length > 16 ? (Eval("Name") as string).Substring(0, 16) : Eval("Name")%>
                                                    </h5>
                                                    <div class="center">
                                                        <asp:Image Width="100px" ID="btnPerformanceImage" runat="server" Height="75px"></asp:Image>
                                                    </div>
                                                </li>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ul>
                                </asp:Panel>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                </tr>
            </table>
        </div>
        </div>

任何人都可以指出我正确的方向吗

4

1 回答 1

1

无论您使用更新面板还是其他任何东西,asp.net 中的每个帖子都必须触发 Page_Load 事件,这是 asp.net 的正常行为,

并尝试将下拉列表放在更新面板中,这样当您更改所选项目时它不会执行完整的回发:

<asp:Panel ID="Panel2" runat="server">
                            <asp:Label ID="lblResultsDuration" runat="server" CssClass="label" ForeColor="Black">View Results since the last </asp:Label>
</asp:Panel>
     <asp:UpdatePanel ID="MainGridUpdatePanel" runat="server">
                            <Triggers>
                                <asp:PostBackTrigger ControlID="btn15MIN"  />
                                <asp:PostBackTrigger ControlID="ddlDuration"/>
                            </Triggers>

                            <ContentTemplate>
                            <asp:DropDownList ID="ddlDuration" OnSelectedIndexChanged="ddlDuration_SelectedIndexChanged"
                                runat="server">
                                <asp:ListItem Text="2" Value="2"></asp:ListItem>
                                <asp:ListItem Text="4" Value="4"></asp:ListItem>
                                <asp:ListItem Text="6" Value="6"></asp:ListItem>
                                <asp:ListItem Text="8" Value="8"></asp:ListItem>
                                <asp:ListItem Text="24" Value="24"></asp:ListItem>
                                <asp:ListItem Text="48" Value="48"></asp:ListItem>
                            </asp:DropDownList>
                            <asp:Label ID="lblResultsDuration1" runat="server" CssClass="label">  Hours </asp:Label>


                                <asp:Panel ID="pnlMonitorSummary" runat="server">
                                    <ul id="monitorGallery" class="gallery ui-helper-reset ui-helper-clearfix" style="margin-top: 5px;">
                                        <asp:Repeater ID="rptMonitorSummary" runat="server" OnItemDataBound="rptMonitorSummary_OnItemDataBound">
                                            <ItemTemplate>
                                                <li class="ui-widget-content ui-corner-tr">
                                                    <h5 class="ui-widget-header">
                                                        <%# Eval("Name").ToString().Length > 16 ? (Eval("Name") as string).Substring(0, 16) : Eval("Name")%>
                                                    </h5>
                                                    <div class="center">
                                                        <asp:Image Width="100px" ID="btnPerformanceImage" runat="server" Height="75px"></asp:Image>
                                                    </div>
                                                </li>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ul>
                                </asp:Panel>
                            </ContentTemplate>
                        </asp:UpdatePanel>
于 2013-05-16T16:05:46.123 回答