Sha*_*hin 20 asp.net postback scroll updatepanel
我有一个在ASP.NET Panel中放置的gridview.面板和Gridview都在UpdatePanel中.gridview中有一列导致部分PostBacks.我想在这些回发上保持Panel Scroll位置.有什么办法吗?问候.
Waq*_*aja 40
在asp.net中没有可以解决它的内置工具
但是,这个问题有一个解决方法; 你需要用javascript来处理它.
这里提到了解决方案:在部分PostBack后维护UpdatePanel内的滚动条位置
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />
<script type="text/javascript">
// It is important to place this JavaScript code after ScriptManager1
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, args) {
if ($get('<%=Panel1.ClientID%>') != null) {
// Get X and Y positions of scrollbar before the partial postback
xPos = $get('<%=Panel1.ClientID%>').scrollLeft;
yPos = $get('<%=Panel1.ClientID%>').scrollTop;
}
}
function EndRequestHandler(sender, args) {
if ($get('<%=Panel1.ClientID%>') != null) {
// Set X and Y positions back to the scrollbar
// after partial postback
$get('<%=Panel1.ClientID%>').scrollLeft = xPos;
$get('<%=Panel1.ClientID%>').scrollTop = yPos;
}
}
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Height="300">
<%-- Some stuff which would cause a partial postback goes here --%>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Run Code Online (Sandbox Code Playgroud)
以下是代码快照: -

| 归档时间: |
|
| 查看次数: |
44608 次 |
| 最近记录: |