我将脚本管理器和更新面板放在母版页中。
<div id="nav">
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
</div>
<div id="mainchild">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ContentPlaceHolder ID="HdrContentPlaceholderBody" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
所以这个div在主页面中,我的子页面有一个放置在面板内的网格视图。
<asp:Content ID="pagecontent" ContentPlaceHolderID="HdrContentPlaceholderBody" runat="server">
<asp:Panel ID="pnlAssignRole" runat="server" CssClass="popuppnl" Visible="false">
<div class="close-image">
<asp:ImageButton ID="ImageButton2" ToolTip="Close" runat="server" ImageUrl="~/App_Themes/Images/Close1.png" OnClick="btnAsgnCancel_Click" />
</div>
<table width="100%">
<tr>
<td>
<div style="height: 600px; overflow: auto;">
<asp:GridView ID="grdEmpAssigned">
gridview content
</GridView>
</div>
</td>
</tr>
</table>
</asp:Content>
在gridview上的rowcommand它导致部分回发,我试着将这段javascript放在updatepanel下面,也在mastermanager下面的masterpage和内容页面中,它也没有帮助..我想我不知道在哪里放置这个javascript
<script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
try {
yPos = $get('ctl00_MainContent_scroll').scrollTop;
}
catch (err) { }
}
function EndRequestHandler(sender, args) {
try {
$get('ctl00_MainContent_scroll').scrollTop = yPos;
}
catch (err) { }
}
</script>
请指导我。
答案 0 :(得分:2)
请浏览此链接。这可能对你有帮助。 http://dotnetcrunch.wordpress.com/2011/08/05/maintain-scroll-position-for-the-whole-page-after-asynchronous-postback/
以下是上述链接的代码。把它放在网站的标题部分。
<script type=”text/javascript”>
var xPos, yPos;
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = document.body.scrollLeft;
yPos = documnet.body.scrollTop;
}
function EndRequestHandler(sender, args) {
document.body.scrollLeft = xPos;
document.body.scrollTop = yPos;
}
</script>