Reputation: 31
Inside an UpdatePanel, I have many Checkboxes and I need to set its 'AutoPostback
' to "true
".
Issue:
Let's assume I have 100 Checkboxes in the panel and I am ticking #50 checbox then the control automatically goes to the top of the page and I have to come down again to tick another checkbox (say #60).
This is really annoying for the users and I am asked to stop this auto-scrolling so that they can stay at the same place and tick another checkboxes. How can I stop my webpage to go on top every time?
Is there any way to disable such behavior? I guess UpdatePanel could be the issue.. If so, how do I disable auto-refershing?
Upvotes: 1
Views: 3171
Reputation: 1
add below in your page directive
MaintainScrollPositionOnPostback="true"
Upvotes: 0
Reputation: 1900
There is no built in way to do this. You will have to write a few Javascript functions to accomplish this:
Have a hidden field lets say 'hfScrollvalue' ( to save and reset scroll position )
Write a JS method "GetScrollPosition", to get the scroll position of the panel and save in your hidden field
Write a JS method "SetScrollPosition" to get the scroll position from the hidden field and set it back to the panel
You can then call the SetScrollPosition method when your request is end by adding a handler for this purpose
After the request ends the scroll position is set again by update panel. So you can give a bit delay in setting your value to the panel scroll position. You can do so by using setTimeout method of Javascript. so by this delay your saved position will be set on the panel after the ajax processing is done
function GetScrollPosition() {
document.getElementById('<%= hfScrollvalue.ClientID %>').value = document.getElementById('<%= Panel1.ClientID %>').scrollTop;
}
function SetScrollPosition() {
document.getElementById('<%= Panel1.ClientID %>').scrollTop = document.getElementById('<%= hfScrollvalue.ClientID %>').value;
}
}
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
function EndRequest(sender, args) {
setTimeout('SetScrollPosition()', 60);
}
If you are working with a TextBox, that is inside an UpdatePanel, that is also tied to a Timer, then you can to something like this:
Sys.Application.add_init(DownloadInit);
function DownloadInit(sender) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
}
function SetScrollPosition() {
var textArea = document.getElementById('<%=TextBox1.ClientID%>');
textArea.scrollTop = textArea.scrollHeight;
}
function EndRequest(sender, args) {
SetScrollPosition();
}
Upvotes: 0
Reputation: 226
Either stop using the UpdatePanel, or set the UpdateMode to Conditional.
If the UpdateMode property is set to Conditional, the UpdatePanel control’s content is updated when one of the following is true:
Upvotes: 1