我有一个带有溢出-y:auto 的网格视图。网格视图位于更新面板内,该面板包含在用户控件中。此用户控件使用 ajax 模式弹出扩展器显示。现在,这个 gridview 可能有数百个项目,如果用户必须选择一个项目,那么异步回发会再次重新加载弹出窗口并且滚动位置丢失。我也尝试使用链接http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx上发布的解决方案,但没有运气。不确定我是否放错了javascript代码。
这是我有模态弹出扩展器的地方。
<asp:Panel ID="pnlShowDirectMailMedium" runat="server" Visible="false" HorizontalAlign="Center">
<uc2:DirectMailMedium ID="ucDirectMailMedium" runat="server" OnCloseEvent="ucDirectMailMedium_CloseEvent" />
<asp:HiddenField ID="hfCloseDMMedium" runat="server" />
</asp:Panel>
<cc1:ModalPopupExtender ID="mpeDirectMailMedium" runat="server" BackgroundCssClass="Modal"
TargetControlID="hfCloseDMMedium" PopupControlID="pnlShowDirectMailMedium" OkControlID="hfCloseDMMedium"
CancelControlID="hfCloseDMMedium" Drag="true" RepositionMode="None" />
这是我拥有gridview的实际用户控件。
<asp:Panel ID="pnlDirectMail" runat="server">
<asp:UpdatePanel ID="upDirectMail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="ZipCodeGrid" id="divGrid">
<asp:GridView ID="gvZips" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvZips_RowDataBound"
GridLines="None" Width="870px">
<Columns>
<asp:TemplateField HeaderText="Zip">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:HiddenField ID="hfSelectedId" runat="server" Value='<%# Bind("SelectedId") %>' />
<asp:HiddenField ID="hfID" runat="server" Value='<%# Bind("ID") %>' />
<asp:Label ID="lblZip" runat="server" Text='<%# Bind("Zip") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lblDescription" runat="server" Text="City" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtDescription" runat="server" Text='<%# Bind("Description") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lblSegmentDescHeader" runat="server" Text="Segment" Visible="false" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblSegment" runat="server" Text='<%# Bind("SegmentDesc") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl1Acre50KHeader" runat="server" Text="1 Acre (50K)" Visible="false" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl1Acre50KQty" runat="server" Text='<%# Bind("One50K") %>' Width="50px"
Visible="false" />
<asp:CheckBox ID="chk1Acre50K" runat="server" Checked='<%# Bind("One50KSelected") %>'
OnCheckedChanged="chk1Acre50K_CheckChanged" AutoPostBack="true" Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl1Acre50KPriceHeader" runat="server" Text="Cost" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl1Acre50KCost" runat="server" Text='<%# Bind("One50KCost", "{0:$###,###,##0.00}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl1Acre100KHeader" runat="server" Text="1 Acre (100K)" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl1Acre100KQty" runat="server" Text='<%# Bind("One100K") %>' Width="50px"
Visible="false" />
<asp:CheckBox ID="chk1Acre100K" runat="server" Checked='<%# Bind("One100KSelected") %>'
OnCheckedChanged="chk1Acre100K_CheckChanged" AutoPostBack="true" Visible="false" />
<asp:HiddenField ID="hf1Acre100KCost" runat="server" Value='<%# Bind("One100KCost", "{0:$###,###,##0.00}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl2Acre50KHeader" runat="server" Text="Prospect 2Acre+" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl2Acre50KQty" runat="server" Text='<%# Bind("Two50K") %>' Width="50px" />
<asp:CheckBox ID="chk2Acre50K" runat="server" Checked='<%# Bind("Two50KSelected") %>'
OnCheckedChanged="chk2Acre50K_CheckChanged" AutoPostBack="true" />
<asp:HiddenField ID="hf2Acre50KPrice" runat="server" Value='<%# Bind("Two50KCost", "{0:$###,###,##0.00}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl2Acre100KHeader" runat="server" Text="Prospect 3Acre+" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl2Acre100KQty" runat="server" Text='<%# Bind("Two100K") %>' Width="50px" />
<asp:CheckBox ID="chk2Acre100K" runat="server" Checked='<%# Bind("Two100KSelected") %>'
OnCheckedChanged="chk2Acre100K_CheckChanged" AutoPostBack="true" />
<asp:HiddenField ID="hf2Acre100KPrice" runat="server" Value='<%# Bind("Two100KCost", "{0:$###,###,##0.00}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl3Acre50KHeader" runat="server" Text="3 Acre (50K)" Visible="false" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl3Acre50KQty" runat="server" Text='<%# Bind("Three50K") %>' Visible="false"
Width="50px" />
<asp:CheckBox ID="chk3Acre50K" runat="server" Checked='<%# Bind("Three50KSelected") %>'
OnCheckedChanged="chk3Acre50K_CheckChanged" AutoPostBack="true" Visible="false" />
<asp:HiddenField ID="hf3Acre50KPrice" runat="server" Value='<%# Bind("Three50KCost", "{0:$###,###,##0.00}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lbl3Acre100KHeader" runat="server" Text="3 Acre (100K)" Visible="false" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbl3Acre100KQty" runat="server" Text='<%# Bind("Three100K") %>' Width="50px"
Visible="false" />
<asp:CheckBox ID="chk3Acre100K" runat="server" Checked='<%# Bind("Three100KSelected") %>'
OnCheckedChanged="chk3Acre100K_CheckChanged" AutoPostBack="true" Visible="false" />
<asp:HiddenField ID="hf3Acre100KPrice" runat="server" Value='<%# Bind("Three100KCost", "{0:$###,###,##0.00}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:LinkButton ID="lblOccupiedHousingUnit" runat="server" Text="Housing Unit" Visible="false"
ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtOccupiedHousingUnit" runat="server" Text='<%# Bind("OccupiedHousingUnit") %>'
Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:LinkButton ID="lblHouseholdIncome" runat="server" Text="Household Income" Visible="false"
ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtHouseholdIncome" runat="server" Text='<%# Bind("HouseholdIncome", "{0:$###,###,##0.00}") %>'
Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:LinkButton ID="lblDistancetoSite" runat="server" Text="Distance" Visible="false"
ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtDistancetoSite" runat="server" Text='<%# Bind("DistancetoSite") %>'
Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:LinkButton ID="lblAverageIncome" runat="server" Text="Home Value" Visible="false"
ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtAverageIncome" runat="server" Text='<%# Bind("AverageIncome", "{0:$###,###,##0.00}") %>'
Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lblRuralPct" runat="server" Text="% Rural" Visible="false" ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtRuralPct" runat="server" Text='<%# Bind("RuralPct") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lblLawnGarden" runat="server" Text="Lawn & Garden" Visible="false"
ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtLawnGarden" runat="server" Text='<%# Bind("LawnGarden") %>' Visible="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
<HeaderTemplate>
<asp:Label ID="lblLawnGardenEquipment" runat="server" Text="Lawn & Garden Equipment"
Visible="false" ForeColor="White" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtLawnGardenEquipment" runat="server" Text='<%# Bind("LawnGardenEquipment") %>'
Visible="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="HeaderFreez" />
<AlternatingRowStyle BackColor="#E4E4E4" />
<RowStyle BackColor="#F7F7F7" />
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
有人可以告诉我该怎么做。仅供参考 - 脚本管理器位于母版页上。