Maintain a scrollable gridview position on postback inside update panel
<p>I have a gridview with overflow-y:auto. The gridview is inside an update panel which is wrapped in a user control. This usercontrol is displayed using the ajax modal pop up extender. Now, this gridview could have hundreds of items, if a user would have to select an item, then the async postback reloads the popup again and the scroll position is lost. I tried with the solution posted on the link <a href="http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx" rel="nofollow">http://weblogs.asp.net/andrewfrederick/archive/2008/03/04/maintain-scroll-position-after-asynchronous-postback.aspx</a> as well but no luck. Not sure if I am misplacing the javascript code.</p>

<p>This is where I have the modal pop up extender.</p>

<pre><code>&lt;asp:Panel ID="pnlShowDirectMailMedium" runat="server" Visible="false" HorizontalAlign="Center"&gt;
        &lt;uc2:DirectMailMedium ID="ucDirectMailMedium" runat="server" OnCloseEvent="ucDirectMailMedium_CloseEvent" /&gt;
        &lt;asp:HiddenField ID="hfCloseDMMedium" runat="server" /&gt;
    &lt;/asp:Panel&gt;
    &lt;cc1:ModalPopupExtender ID="mpeDirectMailMedium" runat="server" BackgroundCssClass="Modal"
        TargetControlID="hfCloseDMMedium" PopupControlID="pnlShowDirectMailMedium" OkControlID="hfCloseDMMedium"
        CancelControlID="hfCloseDMMedium" Drag="true" RepositionMode="None" /&gt;
</code></pre>

<p>This is the actual user control where i have the gridview.</p>

<pre><code>&lt;asp:Panel ID="pnlDirectMail" runat="server"&gt;
&lt;asp:UpdatePanel ID="upDirectMail" runat="server" UpdateMode="Conditional"&gt;
    &lt;ContentTemplate&gt;
&lt;div class="ZipCodeGrid" id="divGrid"&gt;
                            &lt;asp:GridView ID="gvZips" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvZips_RowDataBound"
                                GridLines="None" Width="870px"&gt;
                                &lt;Columns&gt;
                                    &lt;asp:TemplateField HeaderText="Zip"&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:HiddenField ID="hfSelectedId" runat="server" Value='&lt;%# Bind("SelectedId") %&gt;' /&gt;
                                            &lt;asp:HiddenField ID="hfID" runat="server" Value='&lt;%# Bind("ID") %&gt;' /&gt;
                                            &lt;asp:Label ID="lblZip" runat="server" Text='&lt;%# Bind("Zip") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lblDescription" runat="server" Text="City" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtDescription" runat="server" Text='&lt;%# Bind("Description") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lblSegmentDescHeader" runat="server" Text="Segment" Visible="false" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lblSegment" runat="server" Text='&lt;%# Bind("SegmentDesc") %&gt;' Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl1Acre50KHeader" runat="server" Text="1 Acre (50K)" Visible="false" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl1Acre50KQty" runat="server" Text='&lt;%# Bind("One50K") %&gt;' Width="50px"
                                                Visible="false" /&gt;
                                            &lt;asp:CheckBox ID="chk1Acre50K" runat="server" Checked='&lt;%# Bind("One50KSelected") %&gt;'
                                                OnCheckedChanged="chk1Acre50K_CheckChanged" AutoPostBack="true" Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl1Acre50KPriceHeader" runat="server" Text="Cost" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl1Acre50KCost" runat="server" Text='&lt;%# Bind("One50KCost", "{0:$###,###,##0.00}") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl1Acre100KHeader" runat="server" Text="1 Acre (100K)" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl1Acre100KQty" runat="server" Text='&lt;%# Bind("One100K") %&gt;' Width="50px"
                                                Visible="false" /&gt;
                                            &lt;asp:CheckBox ID="chk1Acre100K" runat="server" Checked='&lt;%# Bind("One100KSelected") %&gt;'
                                                OnCheckedChanged="chk1Acre100K_CheckChanged" AutoPostBack="true" Visible="false" /&gt;
                                            &lt;asp:HiddenField ID="hf1Acre100KCost" runat="server" Value='&lt;%# Bind("One100KCost", "{0:$###,###,##0.00}") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl2Acre50KHeader" runat="server" Text="Prospect 2Acre+" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl2Acre50KQty" runat="server" Text='&lt;%# Bind("Two50K") %&gt;' Width="50px" /&gt;
                                            &lt;asp:CheckBox ID="chk2Acre50K" runat="server" Checked='&lt;%# Bind("Two50KSelected") %&gt;'
                                                OnCheckedChanged="chk2Acre50K_CheckChanged" AutoPostBack="true" /&gt;
                                            &lt;asp:HiddenField ID="hf2Acre50KPrice" runat="server" Value='&lt;%# Bind("Two50KCost", "{0:$###,###,##0.00}") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl2Acre100KHeader" runat="server" Text="Prospect 3Acre+" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl2Acre100KQty" runat="server" Text='&lt;%# Bind("Two100K") %&gt;' Width="50px" /&gt;
                                            &lt;asp:CheckBox ID="chk2Acre100K" runat="server" Checked='&lt;%# Bind("Two100KSelected") %&gt;'
                                                OnCheckedChanged="chk2Acre100K_CheckChanged" AutoPostBack="true" /&gt;
                                            &lt;asp:HiddenField ID="hf2Acre100KPrice" runat="server" Value='&lt;%# Bind("Two100KCost", "{0:$###,###,##0.00}") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl3Acre50KHeader" runat="server" Text="3 Acre (50K)" Visible="false" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl3Acre50KQty" runat="server" Text='&lt;%# Bind("Three50K") %&gt;' Visible="false"
                                                Width="50px" /&gt;
                                            &lt;asp:CheckBox ID="chk3Acre50K" runat="server" Checked='&lt;%# Bind("Three50KSelected") %&gt;'
                                                OnCheckedChanged="chk3Acre50K_CheckChanged" AutoPostBack="true" Visible="false" /&gt;
                                            &lt;asp:HiddenField ID="hf3Acre50KPrice" runat="server" Value='&lt;%# Bind("Three50KCost", "{0:$###,###,##0.00}") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lbl3Acre100KHeader" runat="server" Text="3 Acre (100K)" Visible="false" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lbl3Acre100KQty" runat="server" Text='&lt;%# Bind("Three100K") %&gt;' Width="50px"
                                                Visible="false" /&gt;
                                            &lt;asp:CheckBox ID="chk3Acre100K" runat="server" Checked='&lt;%# Bind("Three100KSelected") %&gt;'
                                                OnCheckedChanged="chk3Acre100K_CheckChanged" AutoPostBack="true" Visible="false" /&gt;
                                            &lt;asp:HiddenField ID="hf3Acre100KPrice" runat="server" Value='&lt;%# Bind("Three100KCost", "{0:$###,###,##0.00}") %&gt;' /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:LinkButton ID="lblOccupiedHousingUnit" runat="server" Text="Housing Unit" Visible="false"
                                                ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtOccupiedHousingUnit" runat="server" Text='&lt;%# Bind("OccupiedHousingUnit") %&gt;'
                                                Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:LinkButton ID="lblHouseholdIncome" runat="server" Text="Household Income" Visible="false"
                                                ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtHouseholdIncome" runat="server" Text='&lt;%# Bind("HouseholdIncome", "{0:$###,###,##0.00}") %&gt;'
                                                Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:LinkButton ID="lblDistancetoSite" runat="server" Text="Distance" Visible="false"
                                                ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtDistancetoSite" runat="server" Text='&lt;%# Bind("DistancetoSite") %&gt;'
                                                Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:LinkButton ID="lblAverageIncome" runat="server" Text="Home Value" Visible="false"
                                                ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtAverageIncome" runat="server" Text='&lt;%# Bind("AverageIncome", "{0:$###,###,##0.00}") %&gt;'
                                                Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lblRuralPct" runat="server" Text="% Rural" Visible="false" ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtRuralPct" runat="server" Text='&lt;%# Bind("RuralPct") %&gt;' Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lblLawnGarden" runat="server" Text="Lawn &amp; Garden" Visible="false"
                                                ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtLawnGarden" runat="server" Text='&lt;%# Bind("LawnGarden") %&gt;' Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;HeaderStyle HorizontalAlign="Center" /&gt;
                                        &lt;ItemStyle HorizontalAlign="Center" /&gt;
                                        &lt;HeaderTemplate&gt;
                                            &lt;asp:Label ID="lblLawnGardenEquipment" runat="server" Text="Lawn &amp; Garden Equipment"
                                                Visible="false" ForeColor="White" /&gt;
                                        &lt;/HeaderTemplate&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="txtLawnGardenEquipment" runat="server" Text='&lt;%# Bind("LawnGardenEquipment") %&gt;'
                                                Visible="false" /&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                &lt;/Columns&gt;
                                &lt;HeaderStyle CssClass="HeaderFreez" /&gt;
                                &lt;AlternatingRowStyle BackColor="#E4E4E4" /&gt;
                                &lt;RowStyle BackColor="#F7F7F7" /&gt;
                            &lt;/asp:GridView&gt;
                        &lt;/div&gt;
&lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;
</code></pre>

<p></p>

<p>Could someone give me an insight on what to do. FYI - The scriptmanager is on the master page.</p>
