0

试图弄清楚如何挂钩一些 Web 部件动词事件;具体来说,我想知道用户何时最小化或恢复任何 Web 部件,以及是哪一个。我不在共享点平台上——严格来说是 asp.net (4) ajax (2)。

我在 Web 部件的页面加载中调用以下代码(我的 Web 部件继承了 UserControl 并实现了 IWebPart):

Sub test_WebPartZoneVerbEventHandlers()

    Dim i As Integer = 0

    For Each z As WebPartZone In WebPartManager.GetCurrentWebPartManager(Me.Page).Zones
        Dim restoreVerb As WebPartVerb = z.RestoreVerb
        Dim minimizeVerb As WebPartVerb = z.MinimizeVerb
        If Not IsNothing(restoreVerb) Then
            If Not IsNothing(restoreVerb.ClientClickHandler) Then
                testTextArea.InnerHtml = testTextArea.InnerHtml & i & "<br/>" & restoreVerb.ClientClickHandler
            End If

            If Not IsNothing(restoreVerb.ServerClickHandler) Then
                testTextArea.InnerHtml = testTextArea.InnerHtml & i & "<br/>" & restoreVerb.ServerClickHandler().ToString()

            End If
        End If

        If Not IsNothing(minimizeVerb) Then
            If Not IsNothing(minimizeVerb.ClientClickHandler) Then
                testTextArea.InnerHtml = testTextArea.InnerHtml & i & "<br/>" & minimizeVerb.ClientClickHandler
            End If

            If Not IsNothing(minimizeVerb.ServerClickHandler) Then
                testTextArea.InnerHtml = testTextArea.InnerHtml & i & "<br/>" & minimizeVerb.ServerClickHandler().ToString()

            End If

        End If

        i = i + 1
    Next

End Sub

但我没有得到处理程序的任何名称。这是输出(testTextArea 的内容):

0<br/>0<br/>1<br/>1<br/>2<br/>2<br/>0<br/>0<br/>1<br/>1<br/>2<br/>2<br/>

任何人都知道为什么客户端/服务器单击处理程序没有显示任何内容?

4

1 回答 1

0

无法弄清楚事件名称是什么,坦率地说,我已经厌倦了 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);
};
于 2012-04-20T18:23:55.850 回答