I have one update panel inside which I have datalist.
This update panel triggers every 1 second to retrieve the data from db.
I have kept this update panel inside a vertical scroll enabled div tag.
But when I get 开发者_运维百科new data, the scroll bar is not adjusting automatically !!!
I have tried maintainscrollback option but its not working.
Is there any option to maintain the scroll bar to it original position after the updatepanel triggers?
Please try this:
<script>
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(function(){
window.dTop = document.getElementById('divIdHere').scrollTop;
});
prm.add_endRequest(function(){
setTimeout(function(){
document.getElementById('divIdHere').scrollTop = window.dTop;
},100);
});
</script>
Here is what I prefer to avoid JavaScript, which needs to adjust scroll position each and every refresh/update...
I guess you must have designed page like below
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
<ContentTemplate>
<div style="height: 400px/300px; overflow-y:scroll;">
<asp:DataList ID="DataList1" runat="server">
....
</asp:DataList>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Change it to some thing like this should take care of scroll issue
<div style="height: 400px/300px; overflow-y:scroll;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional/Always">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server">
....
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
I was facing the same problem for a webpage I was working on wherein after the panel update the scroll bar didnt work. Putting the UpdatePanel tag inside the div tag solved my issue.
So, change the below
<UpdatePanel>
<ContentTemplate>
<div>
</div>
</ContentTemplate>
</UpdatePanel>
to,
<div>
<UpdatePanel>
<ContentTemplate>
</ContentTemplate>
</UpdatePanel>
</div>
精彩评论