Tuesday, 20 December 2011

How to Set the position of Page when post back

Some times it happens that our web have a Grid View and Data Grid Contained lots of rows. Which makes Scrolling in Your page. If we clicks on a row and its redirect to another page then The Grid View and Data Grid Becomes Comes on Starting Position of Gridview or DataGrid. For Setting Your Grid View and Data Grid On Last Row Position the Given Below Property can be used.

Property of Page:

MaintainScrollPositionOnPostback ="true"


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Reports.aspx.vb" Inherits="Reports" MaintainScrollPositionOnPostback ="true" %>

Note: If your Grid is inside the Update panel then will not work. For Update Panel we use Given Below Process:


1. Put Given Below Script under the Script Manager tag.

   <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <script type="text/javascript" language="javascript">
    var prmExotic = Sys.WebForms.PageRequestManager.getInstance();

    function pageLoaded(sender, args) {


     function Exotic()
     document.getElementById("divExotic").scrollTop =document.getElementById("Hidden2").value;
   function FuncExotic()
   var s=document.getElementById("divExotic").scrollTop;




2. Put the Hidden Field Text Box Just below the Body tag.

  <input type="hidden" id="Hidden2" runat="server"           

3. Keep DataGrid and Gridview Control Inside the Given Below Div Tag.

<div runat="server" id="divExotic" style="width:580px;height:700px; overflow-x:hidden; overflow-y:scroll; text-align: left;" onscroll="FuncExotic()">
''------------ Pur Your Grid---------'


No comments:

Post a Comment