无法弄清楚事件名称是什么,坦率地说,我已经厌倦了 UpdatePanels 并考虑完全摆脱它们,但我能够通过覆盖我的 web 部件上的 verbs 属性来解决我的问题。
Imports ((myprojectName)).icBase
Imports System.Web.UI.WebControls.WebParts
''' <summary>
''' Base class for web parts.
''' </summary>
''' <remarks></remarks>
Public MustInherit Class icBaseWebPartControl
Inherits icBaseUserControlAjax
Implements IWebPart, IWebActionable
#Region "IWebPart Properties"
Private _Title As String
Private _TitleUrl As String
Private _TitleIconImageUrl As String
Private _Description As String
Private _CatalogIconImageUrl As String
Public ReadOnly Property Subtitle As String Implements IWebPart.Subtitle
Get
Return Nothing
End Get
End Property
Public Property Title() As String Implements IWebPart.Title
Get
Return Me._Title
End Get
Set(ByVal value As String)
Me._Title = value
End Set
End Property
Public Property Description() As String Implements IWebPart.Description
Get
Return Me._Description
End Get
Set(ByVal value As String)
Me._Description = value
End Set
End Property
Public Property TitleUrl() As String Implements IWebPart.TitleUrl
Get
Return Me._TitleUrl
End Get
Set(ByVal value As String)
Me._TitleUrl = value
End Set
End Property
Public Property TitleIconImageUrl() As String Implements IWebPart.TitleIconImageUrl
Get
Return Me._TitleIconImageUrl
End Get
Set(ByVal value As String)
Me._TitleIconImageUrl = value
End Set
End Property
Public Property CatalogIconImageUrl() As String Implements IWebPart.CatalogIconImageUrl
Get
Return Me._CatalogIconImageUrl
End Get
Set(ByVal value As String)
Me._CatalogIconImageUrl = value
End Set
End Property
''' <summary>
''' Gives us some functionality of a full web part without actually extending WebPart. (Me is only an IWebPart, not a true WebPart)
''' </summary>
''' <remarks></remarks>
Public ReadOnly Property WebPart() As WebPart
Get
Dim wpm As WebPartManager = WebPartManager.GetCurrentWebPartManager(Me.Page)
Return wpm.WebParts(Me.ID)
End Get
End Property
#End Region
Public Overridable ReadOnly Property Verbs As System.Web.UI.WebControls.WebParts.WebPartVerbCollection Implements System.Web.UI.WebControls.WebParts.IWebActionable.Verbs
Get
Dim minimizeVerb As WebPartVerb = New WebPartVerb(ID & "minimizeVerb", AddressOf VerbMinimize, "OnMinimizeClicked('" & Me.ID & "')") With {.Text = "Minimize", .Description = "Minimize this web part"}
Dim restoreVerb As WebPartVerb = New WebPartVerb(ID & "restoreVerb", AddressOf VerbRestore, "OnRestoreClicked('" & Me.ID & "')") With {.Text = "Restore", .Description = "Restore this web part"}
Dim collection As Collection = New Collection
Dim returnValue As New WebPartVerbCollection
If Me.WebPart.ChromeState = PartChromeState.Minimized Then
collection.Add(restoreVerb)
returnValue = New WebPartVerbCollection(collection)
End If
If Me.WebPart.ChromeState = PartChromeState.Normal Then
collection.Add(minimizeVerb)
returnValue = New WebPartVerbCollection(collection)
End If
Return returnValue
End Get
End Property
Protected Shared Sub VerbRestore(ByVal sender As Object, ByVal e As WebPartEventArgs)
e.WebPart.ChromeState = PartChromeState.Normal
End Sub
Protected Shared Sub VerbMinimize(ByVal sender As Object, ByVal e As WebPartEventArgs)
e.WebPart.ChromeState = PartChromeState.Minimized
End Sub
End Class
然后我在上面调用的客户端脚本中执行以下操作:
// fired when user clicks restore on any web part
function OnRestoreClicked(webPartID) {
switch (webPartID) {
case 'ucMyTimekeeping':
// don't need to refresh any update panels in this case, because none of the controls in timekeeping are server-side
// (unlike files and docs, which have server-side tab containers and tabs)
dbLoadTime();
break;
case 'ucMyDocuments':
//wait a few milliseconds for the server to un-hide the web part (see icBaseWebPartControl.vb)
//hpTODO: There has GOT to be a better way to do this... maybe autopostback on the restore link, but not sure how to go about that.
setTimeout(function () {
HpDocs.UpdatePanel();
dbLoadDocs();
}, 200);
break;
case 'ucMyFiles':
// hpTODO: same as for ucMyDocuments
setTimeout(function () {
HpFiles.UpdatePanel();
dbLoadFiles();
}, 200);
break;
default:
__doPostBack(webPartID, '');
}
// return false;
};
下面是 UpdatePanel() 函数的样子:
// do partial postback on the update panel inside the My Files .ascx
HpFiles.UpdatePanel = function () {
var myFiles = $("[id$='_upMyFiles']").attr('id');
__doPostBack(myFiles);
};