Hello,
I would like to preserve a grid's vertical scroll position across asynchronous postbacks.
I have an Infragistics UltraWebGrid control inside a div, which is inside an UpdatePanel, on a page with 4 UpdatePanel controls. Each UpdatePanel has UpdateMode = Conditional and I will typically .Update() 3 or 4 of the UpdatePanels during the same event. I want to either remember or reset the vertical scroll position across asynchronous postbacks. Setting the grid's div.scrollTop value works. The problem is scrollTop gets reset back to 0 on asynchronous postbacks by line 1321, "window.scrollTo(...)" in function "Sys$WebForms$PageRequestManager$_scriptsLoadComplete" in file "MicrosoftAjaxWebForms.debug.js". I have currently kludged the code using a setTimeout("...grid.DivElement.scrollTop = ...", 100);, which I call from the Sys.WebForms.PageRequestManager's endRequestHandler. The timeout was the only way I could find to set scrollTop to execute after line 1321 above. On aysnchronous postbacks, you can see the scroll position get reset to zero (line 1321), then scroll to the correct position.
Ideally, I would like to prevent line 1321 from executing. I have tried, to no avail, setting the pageRequestManager._scrollPosition to null during various events, (pageLoaded, initializeRequest, beginRequest, endRequest). However, if line 1321 must execute, then I would like to apply my scrollTop code w/o using the setTimeout function since I suspect the timeout duration that works on my machine may not work on slower or busier machines.
Does anyone have any suggestions?
-Greg Peters
Thanks for the response. I did see to do this but I can't because I'm using Master Pages and don't have access to the grid from the master page. Any other suggestions?
Thanks again!
I ended up using the setTimeout. It is working in all cases tested, but it still makes me uneasy.
I store the scroll position in a hidden field on the server, before I .Update() the panel. Then call the following javascript function at the end of the Sys.WebForms.PageRequestManager's endRequestHandler.
function setTopGridScroll(){ var grid;
grid = igtbl_getGridById(id_gridTop); if (grid != null) { var gridScroll = document.getElementById(id_hfgridtopscroll); if (gridScroll != null) { var nVal = parseInt(gridScroll.value, 10); if (nVal >= 0) { var sCmd = "igtbl_getGridById(id_gridTop).DivElement.scrollTop = " + nVal; setTimeout(sCmd, 100); } } }}
I am running into the same issue. Has anyone come up with an appropriate solution?
Thanks.
Hi Rumen,
Thanks for the idea, but I need to scroll the rows under stationary column headers. So, it seems I must let the grid control the scrolling, rather than the parent div.
Thanks again.
Just a suggestion - is it possible to not set Height for the UltraWebGrids on the page at all (so that they span all the way down) but rather set the height of their respective <div> containers (you can add <div> containers if you do not have ones set), e.g.
<div style="height: 500px; overflow: scroll">
<igtbl:UltraWebGrid ...
</div>
This way, the scrollbars will be controlled by the parent <div> rather than the grid itself and you will have better control on them durng UpdatePanel updates (and you will not rely on like 1321 for setting the scrollbar position).
Just a suggestion, hope it helps.