lunes, 7 de julio de 2014

Force a DIV to keep the scroll position after callbacks within an AJAX enabled UpdatePanel in ASPX

Usually when a callback occurs within an UpdatePanel and we have a div with scrolls the position of the scroll get's lost so what we need to do is implement the next JS code.

The trick is the handling of the begin and the end of the request using the PageRequestManager instance, see the next code.



<script language="javascript">
         var iX, iY; // Posiciones X y Y del scroll del div 
         var divID; // Identificador del DIV 
         var rMAN= Sys.WebForms.PageRequestManager.getInstance(); //Instancia del Page Request Manager del lado del cliente
       
         divID = "scrollableDIV";

         rMAN.add_beginRequest(beginRequestHnd);
         rMAN.add_endRequest(endRequestHnd);

         //función que se invoca al iniciar el request causado por un callback / postback asincrono
         function beginRequestHnd(sender, args) {
             iX = document.getElementById(divID).scrollLeft;
             iY = document.getElementById(divID).scrollTop;
         }
         //función que se invoca al finalizar el request causado por un callback / postback asincrono
         function endRequestHnd(sender, args) {
             document.getElementById(divID).scrollLeft = iX;
             document.getElementById(divID).scrollTop = iY;
         }
    </script>

<!--  Los siguientes tags solo como referencia de donde ubicar el código fuente de JS -->
</ContentTemplate>
</asp:UpdatePanel>

Transacciones Fiori

  /UI2/CACHE Register service for UI2 cache use /UI2/CACHE_DEL Delete cache entries /UI2/CHIP Chip Registration /UI2/CUST Customizing of UI ...