Hello friends,
Sometimes we need to maintain scroll position of the page after postback due to dropdown change or button click in that case follow the code.
next take one hidden field to maintain scrol value.
put the script in the head part.
finally register the scrol function in last line of the event in code behind page.
Sometimes we need to maintain scroll position of the page after postback due to dropdown change or button click in that case follow the code.
if Dropdown Control : onChange="ab();"
if Button Control : onClientClick ="ab();"
if Button Control : onClientClick ="ab();"
next take one hidden field to maintain scrol value.
<asp:HiddenField ID="TOS" runat="server" />
put the script in the head part.
<script type="text/javascript">
function ab() {
$("#<%= TOS.ClientID %>").val($(window).scrollTop());
}
function scrol() {
setTimeout(function () { $(window).scrollTop($("#<%= TOS.ClientID %>").val()); }, 1);
}
</script>
function ab() {
$("#<%= TOS.ClientID %>").val($(window).scrollTop());
}
function scrol() {
setTimeout(function () { $(window).scrollTop($("#<%= TOS.ClientID %>").val()); }, 1);
}
</script>
finally register the scrol function in last line of the event in code behind page.
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "JavaScript:scrol();", true);
No comments:
Post a Comment