title: Page scrolls back on each post back
body: <p>i have successfully completed my web application for an organization and it works up to expectations but i noticed one problem and tried to cure it via searching on Google and asking seniors but none of these helped much.</p>
  
  <p>Problem: I have multiple drop downs lists on page, in which selecting value in one drop down triggers the loading of another drop down i.e. Country > cities situation, problem is that whenever i click any value it scrolls page to the top and i have to scroll back again then again and again which realy looks bad and unprofessional. Please help me.</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="frmReceivedSms.aspx.cs" Inherits="SmsComplaints" %&gt;
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;
  &lt;%@ Register assembly="Microsoft.ReportViewer.WebForms,Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $("#btnSendSms").hide();
              $("#btnDelete").hide();
              $("#btnCancel").hide();
              $("#lblSelectedID-Span").hide();
              $("#txtSelectedID-Span").hide();
              var showHide = $("#HiddenFieldShowHideButtons").val();
              if (showHide == "True") {
                  $("#btnSendSms").show();
                  $("#btnDelete").show();
                  $("#btnCancel").show();
                  $("#lblSelectedID-Span").show();
                  $("#txtSelectedID-Span").show();
                  $("#buttonSearch").hide();
                  $("#Save-Span").hide();
                  $("#HiddenFieldShowHideButtons").val("False");
              }
              $("#btnSendSms").click(function () {
                  $("#ConfirmMsg").text("Are you sure to update this record?");
                  $("#Delete-Span").hide();
                  $("#lblSelectedID-Span").hide();
                  $("#txtSelectedID-Span").hide();
                  $("#Save-Span").show();
                  $("#buttonSearch").show();
                  $("#Update-Span").show();
                  $("#btnSendSms").hide();
                  $("#btnDelete").hide();
                  $("#btnCancel").hide();
                  $("#ModalConfirmAction").modal({ show: true })
              });
  
              $("#btnDelete").click(function () {
                  $("#ConfirmMsg").text("Are you sure to delete this record?");
                  $("#Update-Span").hide();
                  $("#lblSelectedID-Span").hide();
                  $("#txtSelectedID-Span").hide();
                  $("#Delete-Span").show();
                  $("#Save-Span").show();
                  $("#buttonSearch").show();
                  $("#btnDelete").hide();
                  $("#btnSendSms").hide();
                  $("#btnCancel").hide();
                  $("#ModalConfirmAction").modal({ show: true })
              });
  
              $("#btnCancel").click(function () {
                  $("#btnSendSms").hide();
                  $("#btnDelete").hide();
                  $("#btnCancel").hide();
                  $("#lblSelectedID-Span").hide();
                  $("#txtSelectedID-Span").hide();
                  $("#buttonSearch").show();
                  $("#Save-Span").show();
                  ClearTextBoxes();
              });
          });
  
          function ClearTextBoxes() {
              $("input[type=text]").each(function () {
                  $(this).val("");
  
              });
          }
  
          function validate() {
  
              var setValue = false;
              var NotificationSummary = new Array();
              var fields = new Array("Admin Role");
              var txtboxes = new Array($("#txtAdminName"));
  
              $(txtboxes).each(function (index) {
                  if ($(this).val() == "") {
                      NotificationSummary[index] = fields[index];
                      setValue = true;
                  }
              });
              if (setValue == true) {
                  $("#ConfirmMsg").text = NotificationSummary.join(",");
                  $("#ModalConfirmAction").modal({ show: true })
              }
              return setValue;
          }
  
          $("#Save-Span").click(function () {
              validate();
          });
      &lt;/script&gt;
  
  
  &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
  &lt;/asp:ScriptManager&gt;
  
  &lt;%--&lt;script type="text/javascript"&gt;  //Maintain scroll on post back but doesn't load values in relevant drop down
      var xPos, yPos;
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      prm.add_beginRequest(BeginRequestHandler);
      prm.add_endRequest(EndRequestHandler);
      function BeginRequestHandler(sender, args) {
          xPos = $get('ContentPlaceHolder1').scrollLeft;
          yPos = $get('ContentPlaceHolder1').scrollTop;
      }
      function EndRequestHandler(sender, args) {
          $get('ContentPlaceHolder1').scrollLeft = xPos;
          $get('ContentPlaceHolder1').scrollTop = yPos;
      }
  &lt;/script&gt;--%&gt;
  
              &lt;div class="widget"&gt;
                  &lt;div class="widget-header"&gt;
                          &lt;div class="title"&gt;
                              Received Complaints Via Sms&amp;nbsp;
                          &lt;/div&gt;
                          &lt;!-- widget title--&gt;
                  &lt;/div&gt; &lt;!-- widget header --&gt;
  
                          &lt;div class="widget-body"&gt;
                          &lt;div class="row-fluid"&gt;
        &lt;!-- cons start --&gt;
             &lt;div class="shortcut-group"&gt;
              &lt;asp:HiddenField ID="HiddenFieldSetMessage" runat="server" 
                   ClientIDMode="Static"/&gt;
              &lt;asp:HiddenField ID="HiddenFieldShowMessage" runat="server" 
                   ClientIDMode="Static"/&gt;
              &lt;asp:HiddenField ID="HiddenFieldIsValidDropDownValue" runat="server" 
                   ClientIDMode="Static" /&gt;
  
  
          &lt;asp:UpdatePanel ID="updGridViewSMS" runat="server" UpdateMode="Conditional"&gt;
            &lt;ContentTemplate&gt;
              &lt;label&gt;&lt;b&gt;Search By Date Range&lt;/b&gt;&lt;/label&gt;
              &lt;asp:Label ID="lblDateFrom" runat="server" Text="From"&gt;&lt;/asp:Label&gt;
              &lt;asp:TextBox ID="txtFromDate" runat="server" &gt;&lt;/asp:TextBox&gt;                      
              &lt;asp:CalendarExtender ID="CalendarExtenderFromDate" Format="dd/MMM/yyyy" TargetControlID="txtFromDate" runat="server"&gt;
              &lt;/asp:CalendarExtender&gt;
              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" 
                                  ControlToValidate="txtFromDate" Display="None" ErrorMessage="" 
                                  ForeColor="Red" &gt;
              &lt;/asp:RequiredFieldValidator&gt;
              &lt;asp:Label ID="lblDateTo" runat="server" Text="To"&gt;&lt;/asp:Label&gt;
              &lt;asp:TextBox ID="txtToDate" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;asp:CalendarExtender ID="CalendarExtenderToDate" Format="dd/MMM/yyyy" TargetControlID="txtToDate" runat="server"&gt;
              &lt;/asp:CalendarExtender&gt;
              &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" 
                                  ControlToValidate="txtToDate" Display="None" ErrorMessage="" 
                                  ForeColor="Red" &gt;
              &lt;/asp:RequiredFieldValidator&gt;
              &lt;asp:Button ID="btnSearchByDate"  CssClass="btn btn-success" runat="server" Text="Search" 
                          ClientIDMode="Static"  OnClick="btnSearchByDate_Click" /&gt;
              &lt;asp:ValidationSummary
               HeaderText="Requires Date Range:"
               DisplayMode="SingleParagraph"
               EnableClientScript="true"
               ForeColor="Red"
               runat="server" ID="ValidationSummary1"/&gt;
             &lt;label runat="server" id="lblSelectionMessage" style="color:navy; font-size:12px; font-style:italic" visible="false"&gt;
                 Please select one validity dropdown at a time
             &lt;/label&gt;
             &lt;asp:GridView ID="GridViewSmsComplaints" AllowPaging="True" PageSize="5" runat="server" AutoGenerateColumns="False" CssClass="mGrid" BorderColor="#333333"  Width="650px" OnRowDataBound="GridViewSmsComplaints_RowDataBound" OnPageIndexChanging="GridViewSmsComplaints_PageIndexChanging" &gt;
                 &lt;Columns&gt;
                      &lt;asp:BoundField HeaderText="Sms ID" DataField="ID" /&gt; 
                      &lt;asp:BoundField HeaderText="Recieving Date" DataField="RecievingDate" /&gt;  
                      &lt;%--&lt;asp:BoundField HeaderText="ToMobileNo" DataField="ToMobileNo" /&gt;  --%&gt;
                      &lt;asp:BoundField HeaderText="Complainant Mob No." DataField="FromMobileNo" /&gt; 
                      &lt;asp:BoundField HeaderText="Complaint" DataField="Message" &gt;   
                       &lt;ItemStyle Wrap="True" /&gt;
                      &lt;/asp:BoundField&gt;
                      &lt;asp:TemplateField HeaderText="Complete/InComplete"&gt;
                       &lt;ItemTemplate&gt;
                         &lt;%--&lt;asp:CheckBox ID="ckboxIsComplaint"  runat="server" /&gt;--%&gt;
                         &lt;asp:DropDownList ID="ddlIsComplaint" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlIsComplaint_SelectedIndexChanged"&gt;
                          &lt;asp:ListItem Text="-Select-" Value="-1"&gt;&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Text="InComplete" Value="0"&gt;&lt;/asp:ListItem&gt;
                          &lt;asp:ListItem Text="Complete" Value="1"&gt;&lt;/asp:ListItem&gt;
                         &lt;/asp:DropDownList&gt;
                       &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                 &lt;/Columns&gt;
              &lt;/asp:GridView&gt;    
  
          &lt;br /&gt;
        &lt;asp:Panel ID="pnlBoxesDropDowns" runat="server"&gt;
          &lt;label&gt;Complainant&lt;/label&gt;
          &lt;asp:TextBox ID="txtComplainant" runat="server" CssClass="textField_width"&gt;&lt;/asp:TextBox&gt;
          &lt;asp:RequiredFieldValidator ID="ReqFieldValdiatorComplainant" runat="server" ControlToValidate="txtComplainant" ErrorMessage="Complainant is Required" ForeColor="Red" SetFocusOnError="True" ValidationGroup="Complaints"&gt;Complainant is Required
          &lt;/asp:RequiredFieldValidator&gt;
          &lt;label style="width:400px"&gt;Relevant Region&lt;/label&gt;
          &lt;asp:DropDownList ID="ddlRegions" runat="server" CssClass="DropDown_Width" Width="147px" OnSelectedIndexChanged="ddlRegions_SelectedIndexChanged" AppendDataBoundItems="True"  AutoPostBack="true" &gt;
            &lt;asp:ListItem Value="-1" Selected="True"&gt;-Select-&lt;/asp:ListItem&gt;
          &lt;/asp:DropDownList&gt;
          &lt;asp:RequiredFieldValidator ID="ReqFieldValidatorRegions" runat="server" 
           ControlToValidate="ddlRegions" ErrorMessage="Region is Required" InitialValue="-1"
           ForeColor="Red" ValidationGroup="Complaints"&gt;Region is Required&lt;/asp:RequiredFieldValidator&gt;
  
          &lt;label style="width:400px"&gt;Relevant District&lt;/label&gt;
          &lt;asp:DropDownList ID="ddlDistricts" runat="server" CssClass="DropDown_Width" Width="147px" OnSelectedIndexChanged="ddlDistricts_SelectedIndexChanged" AutoPostBack="true"&gt;
          &lt;/asp:DropDownList&gt;
          &lt;asp:RequiredFieldValidator ID="ReqFieldValidatorDistricts" runat="server" 
           ControlToValidate="ddlDistricts" ErrorMessage="Region is Required" InitialValue="-1"
           ForeColor="Red" ValidationGroup="Complaints"&gt;District is Required&lt;/asp:RequiredFieldValidator&gt;
          &lt;label&gt;Relevant P.Station&lt;/label&gt;
          &lt;asp:DropDownList ID="ddlPoliceStations" runat="server" Width="147px" CssClass="DropDown_Width"&gt;
          &lt;/asp:DropDownList&gt;
          &lt;asp:RequiredFieldValidator ID="ReqFieldValidatorPoliceStations" runat="server" 
           ControlToValidate="ddlPoliceStations" ErrorMessage="Police Station is Required" InitialValue="-1"
           ForeColor="Red" ValidationGroup="Complaints"&gt;Police Station is Required&lt;/asp:RequiredFieldValidator&gt;
          &lt;label&gt;Priority&lt;/label&gt;
          &lt;asp:DropDownList ID="ddlPriority" runat="server"&gt;
              &lt;asp:ListItem Text="Top" Value="1"&gt;&lt;/asp:ListItem&gt;
              &lt;asp:ListItem Text="Normal" Value="2"&gt;&lt;/asp:ListItem&gt;
          &lt;/asp:DropDownList&gt;
        &lt;/asp:Panel&gt;
          &lt;br /&gt;
          &lt;br /&gt;
              &lt;asp:Timer runat="server" Interval="60000" ID="RefreshSmsComplaints" OnTick="RefreshSmsComplaints_Tick" /&gt;
            &lt;/ContentTemplate&gt;
              &lt;Triggers&gt;
                  &lt;asp:AsyncPostBackTrigger ControlID="RefreshSmsComplaints" EventName="Tick" /&gt;
              &lt;/Triggers&gt;
           &lt;/asp:UpdatePanel&gt;
          &lt;asp:Button ID="btnSendSms" ValidationGroup="Complaints"  runat="server" CssClass="btn btn-success"  
              OnClick="btnSendSms_Click" Text="Send Sms" /&gt;
          &lt;%--&lt;asp:Button ID="btnGenerateReport"  CssClass="btn btn-success" runat="server" Text="Generate Report" 
                          ClientIDMode="Static" OnClick="btnGenerateReport_Click" /&gt;--%&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="550px"&gt;
                      &lt;LocalReport ReportPath="Reports\GetReceivedComplaintsReport.rdlc"&gt;
                      &lt;/LocalReport&gt;
          &lt;/rsweb:ReportViewer&gt;
  
  
      &lt;br /&gt;
      &lt;br /&gt;
                              &amp;nbsp
  
  
  
                                       &lt;/div&gt; &lt;!-- shourtcut group"&gt;
                          &lt;!-- cons end --&gt;
  
                                                  &lt;/div&gt; &lt;!-- row fluid --&gt;
                      &lt;/div&gt; &lt;!-- widget body--&gt;
  
              &lt;/div&gt; &lt;!-- widget--&gt;
  
          &lt;div class="clearfix"&gt;&lt;/div&gt;
  
        &lt;!-- Modal --&gt;
  
  
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>even i used maintainscrollbackposition attribute in page directive and code but it doesn't work, i am using firefox. Even i used this code after scriptmanager tag but it works not perfectly like it maintain scroll back position of page but doesn't load values in drop down upon clicking.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var xPos, yPos;
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      prm.add_beginRequest(BeginRequestHandler);
      prm.add_endRequest(EndRequestHandler);
      function BeginRequestHandler(sender, args) {
          xPos = $get('scrollDiv').scrollLeft;
          yPos = $get('scrollDiv').scrollTop;
      }
      function EndRequestHandler(sender, args) {
          $get('scrollDiv').scrollLeft = xPos;
          $get('scrollDiv').scrollTop = yPos;
      }
  &lt;/script&gt;
  </code></pre>