後在Chrome和Safari TabPanel中保持滾動位置我試圖在使用以下編碼設置焦點以跨多個瀏覽器回發控件後保持滾動位置。在IE中可以正常工作,但在Chrome,Firefox和Safari中,當我嘗試重新設置導致回發的控件時,滾動會跳回頂端。我使用scriptmanager.setfocus(control)方法設置焦點。 注意:我指的是選項卡面板中的垂直滾動條,而不是主頁滾動條。如何在設置焦點控制
Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
Dim PostControl As Control = FindControlById(HiddenFieldPostControl.Value)
If PostControl IsNot Nothing Then
Dim sm As ScriptManager = ScriptManager.GetCurrent(Master.Page)
sm.SetFocus(PostControl)
End If
End If
End Sub
//-----------------------------------------------------------------------------------//
// Maintain scroll position in given element or control
//-----------------------------------------------------------------------------------//
var yPos
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
var tb = document.getElementById('MainContent_RightTabContainer_InputTabPanel');
if (tb != null) {
yPos= $get('InputPanel.ClientID').scrollTop;
}
}
function EndRequestHandler(sender, args) {
var tb = document.getElementById('MainContent_RightTabContainer_InputTabPanel');
if (tb != null) {
$get('InputPanel.ClientID').scrollTop = yPos;
}
}
<asp:Panel ID="InputPanel" runat="server" CssClasss="MenuPanel" EnableViewState="False">
...controls
</asp:Panel>
是的,我已經使用MaintainScrollPositionOnPostback但只適用於網頁,而不是一個tabpanel內的滾動條從Page_PreRender事件刪除sm.SetFocus(PostControl)。謝謝。 – TroyS