title: Stop scrolling to the top on a master page with ContentPlaceHolder?
body: <p>I have been pulling my hair on this for 2 days without success.</p>
  
  <p>As you can read in the subject, I am simply trying to stop the web page from scrolling to the top of the page when a user clicks a link in my GridView. But the GridView is within a ContentPlaceHolder which is set at a master page.</p>
  
  <p>I have looked at all the possible solutions via Google, even a new assembly idead to build jscript code at run time but all have failed.</p>
  
  <p>Here is my master page:</p>
  
  <pre><code>&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="Attendance.master.cs" Inherits="Attendance_Attendance" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Attendance&lt;/title&gt;
      &lt;style type="text/css"&gt;
      .timetablecell {
          cursor: pointer;
      }
      .timetablecell:hover {
          background-color: Orange;
      }
      .smalltext {
          font-size: 8pt;
      }
      .classsize {
          font-size: 8pt; display: block;
      }
      .nowrap {
          white-space: nowrap;
      }
      img {
          border: 0;
      }
      &lt;/style&gt;
      &lt;asp:ContentPlaceHolder ID="ContentPlaceHolderHead" runat="server"&gt;
      &lt;/asp:ContentPlaceHolder&gt;
  &lt;/head&gt;
  &lt;body&gt;
       &lt;form id="form1" runat="server"&gt;
          &lt;asp:ScriptManager ID="SMan" runat="server" EnablePageMethods="True"&gt;
          &lt;/asp:ScriptManager&gt;
          &lt;asp:Panel ID="HeaderPanel" runat="server"&gt;
          &lt;table width="100%"&gt;
              &lt;tr valign="middle"&gt;
                  &lt;td style="width: 25%; " valign="middle" align="left" &gt;
                      &lt;img src="../images/blahblah.jpg" alt="Tec-NQ" /&gt;
                  &lt;/td&gt;
                  &lt;td valign="middle" align="center" style="width: 50%"&gt;
                  &lt;asp:Image ID="Image3" runat="server" ImageUrl="~/images/blahblah2.jpg" /&gt;&lt;br /&gt;
                  &lt;asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Times New Roman"
                          Font-Size="1.2em"&gt;BLAHBLAHBLAH&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td style="width:25%" align="right"&gt;
                      &lt;img src="../images/BLAHBLAH3.jpg" alt="BLAHBLAH" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;/asp:Panel&gt;
          &lt;table width="100%"&gt;
              &lt;tr&gt;
                  &lt;td valign="top" style="width:15%"&gt;
                      &lt;asp:Panel ID="MenuPanel" runat="server"&gt;
                      &lt;table&gt;
                        &lt;tr&gt;
                          &lt;td&gt;
                            &lt;h5 style="white-space:nowrap;"&gt;Attendance Menu&lt;/h5&gt;
                          &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                          &lt;td&gt;
                                  &lt;asp:Menu ID="Attendance" ItemWrap="true" Font-Size="10pt" StaticMenuStyle-VerticalPadding="4"
                                      runat="server" StaticMenuItemStyle-VerticalPadding="1"&gt;
                                      &lt;Items&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/ClassAttendance.aspx" Text="Class Attendance"
                                              Value="Class Attendance"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/Classes.aspx" Text="Classes"
                                              Value="Classes"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/Timetable.aspx" Text="Timetable"
                                              Value="Timetable"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/Roster.aspx" Text="Roster"
                                              Value="Roster"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/ApprovedAbsences.aspx" Text="Approved Absences"
                                              Value="Approved Absences"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Default.aspx" Text="Main Menu" Value="Main Menu"&gt;&lt;/asp:MenuItem&gt;
                                      &lt;/Items&gt;
                                      &lt;StaticMenuStyle VerticalPadding="4px" /&gt;
                                  &lt;/asp:Menu&gt;
                                  &lt;asp:Menu ID="AttendanceReports" ItemWrap="true" Font-Size="10pt" StaticMenuStyle-VerticalPadding="4"
                                      runat="server" StaticMenuItemStyle-VerticalPadding="1"&gt;
                                      &lt;Items&gt;
                                          &lt;asp:MenuItem Text="&lt;h5 style='margin-top:10px;margin-bottom:10px'&gt;Reports&lt;/h5&gt;" Selectable="false"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/ClassRoles.aspx" Text="Class Logins"
                                              Value="Class Logins"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/StudentsHereToday.aspx" Text="Students Here Today"
                                              Value="Students Here Today"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/StudentAbsences.aspx" Text="Student Absences"
                                              Value="Student Absences"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/StudentKPI.aspx" Text="Student KPI"
                                              Value="Student KPI"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/AttendanceDetailed.aspx" Text="Attendance Detailed"
                                              Value="Attendance Detailed"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/StudentAttendance.aspx" Text="Attendance Summary"
                                              Value="Attendance Summary"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/AttendanceNotMarked.aspx" Text="Attendance Not Marked"
                                              Value="Attendance Not Marked"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/AttendanceFullTime.aspx" Text="Attendance Full Time"
                                              Value="Attendance Full Time"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/rptsAttendance/default.aspx" Text="Old Attendance Reports"
                                              Value="Old Attendance Reports"&gt;&lt;/asp:MenuItem&gt;
                                          &lt;asp:MenuItem NavigateUrl="~/Attendance/StaffTimetable.aspx" Text="Staff Timetable"
                                              Value="Staff Timetable"&gt;&lt;/asp:MenuItem&gt;
                                      &lt;/Items&gt;
                                      &lt;StaticMenuStyle VerticalPadding="4px" /&gt;
                                  &lt;/asp:Menu&gt;
                          &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                          &lt;td&gt;
                              &lt;asp:ImageButton ID="HelpImageButton" runat="server" ImageUrl="/images/helpsm.jpg" AlternateText="HELP" CausesValidation="false" OnClick="Help_Click" /&gt;
                              &lt;!--a href="/Help/Attendance/ClassAttendance.aspx" target="_blank"&gt;&lt;img src="/images/helpsm.jpg" alt="HELP" border="0"/&gt;&lt;/a--&gt;
                          &lt;/td&gt;
                        &lt;/tr&gt;
                      &lt;/table&gt;
                      &lt;/asp:Panel&gt;
                  &lt;/td&gt;
                  &lt;td valign="top"&gt;
                      &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"&gt;
                      &lt;/asp:ContentPlaceHolder&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is one of the above pages with my GridView ...</p>
  
  <pre><code>     &lt;%@ Page Language="C#" MasterPageFile="~/Attendance/Attendance.master"
      AutoEventWireup="true" CodeFile="ClassAttendance.aspx.cs"
      Inherits="Attendance_ClassAttendance" 
      Title="Class Attendance" Culture="en-AU"%&gt;
  
      &lt;asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
  
  ...
  ...
  ...
  
      &lt;asp:GridView ID="gvStudents" runat="server" AutoGenerateColumns="false" AllowSorting="true" CellPadding="2" ShowFooter="true" DataKeyNames="AttendanceID" 
          OnRowDataBound="GridView_RowDataBound" OnDataBound="GridView_DataBound" EnableSortingAndPagingCallbacks="False"&gt;
  ...
  ...
      &lt;/asp:GridView&gt;
  &lt;/asp:Content&gt;
  
  ...
  ...
  </code></pre>
  
  <p>I've tried several solutions, as mentioned above ...</p>
  
  <p><a href="https://stackoverflow.com/questions/992887/how-to-persist-scroll-position-using-master-page">How to persist scroll position using Master Page?</a>
  <a href="https://stackoverflow.com/questions/11161652/asp-page-scrolls-to-top-on-updatepanel-update">ASP page scrolls to top on UpdatePanel update</a>
  <a href="http://www.dotnetspark.com/links/41291-how-to-prevent-master-page-postback-when.aspx" rel="nofollow noreferrer">http://www.dotnetspark.com/links/41291-how-to-prevent-master-page-postback-when.aspx</a>
  <a href="https://web.archive.org/web/20211020140248/https://www.4guysfromrolla.com/articles/111704-1.aspx" rel="nofollow noreferrer">https://web.archive.org/web/20211020140248/https://www.4guysfromrolla.com/articles/111704-1.aspx</a></p>
  
  <p>The last link looked the most promising, but I think it was written for non-Master page websites that have a simple form.</p>
  
  <p>I also tried the usual solutions to place the SmartNavigation tag and ...</p>
  
  <p><code>Page.MaintainScrollPositionOnPostBack = true;</code></p>
  
  <p>None of the above worked.</p>
  
  <p>I suspect it's because I am using a ContentPlaceHolder? Maybe I should place a <code>&lt;div&gt;&lt;/div&gt;</code> around it? I tried that, but also not working.</p>
  
  <p>Thanks for your support.</p>
  
  <p>Cheers</p>