扩展 Panel 控件—自动维护滚动条位置


我们知道 Page 的 MaintainScrollPositionOnPostBack 属性为 True 时,PostBack 时页面就会自动维护滚动条位置。而在上一篇「维护 Panel 滚动条位置」文章中,也介绍如何利用 HiddenField 来维护 Panel 滚动条的位置;在这篇文章中,我们将利用相同的原理,扩展 Panel 控件,使得 Panel 控件就自动具有此功能。

  我们将继承 Panel 控件下来命名为 TBPanel ,如同 Page 一样,在 TBPanel 中新增一个 MaintainScrollPositionOnPostBack 属性,当MaintainScrollPositionOnPostBack 设定 True 时,TBPanel 就会自动维护 PostBack 时滚动条的位置。

  TBPanel 完整的程序代码如下

 1Imports System
 2Imports System.Collections.Generic
 3Imports System.ComponentModel
 4Imports System.Text
 5Imports System.Web
 6Imports System.Web.UI
 7Imports System.Web.UI.WebControls
 8
 9ToolboxData("<{0}:TBPanel runat=server>")> _
10Public Class TBPanelClass TBPanel
11    Inherits System.Web.UI.WebControls.Panel
12    Private FMaintainScrollPositionOnPostBack As Boolean = False
13
14    /**/'''
15    ''' PostBack 时自动维<<


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3