开发者

Persisting sharepoint EditorPart settings

开发者 https://www.devze.com 2023-03-22 17:50 出处:网络
Inheriting from the System.Web.UI.WebControls.WebParts.EditorPart class I have been shown that it is possible to expose a public property in your VisualWebPart that when updated through the EditorPart

Inheriting from the System.Web.UI.WebControls.WebParts.EditorPart class I have been shown that it is possible to expose a public property in your VisualWebPart that when updated through the EditorPart will be automagically persisted in sharepoint.

The problem I have run into is saving strings and integers works great but when I attempt to persist the value of a collection such as List<String> the开发者_StackOverflow社区 object is not saved.

The code looks like this.

Public Class MyCustomEditorPart
    Inherits EditorPart

    Public Overrides Function ApplyChanges() As Boolean
        VisualWebPart1.TestString = "Test"
        VisualWebPart1.TestList = new List(Of String) ''Add Items....
    End Function

    Public Overrides Sub SyncChanges()
        Dim readString As String = VisualWebPart1.TestString ''Works great
        Dim readList As List(Of String) = VisualWebPart1.TestList ''Always an empty new instance
    End Function

End Class

Public Class VisualWebPart1
    Inherits WebPart

    Public Property TestString As String 
    Public Property TestList As List(Of String)
End Class

Anyone care to provide some insight? Can you only save primitives using this technique?


You are right, web part can only save primitive types into personalization store by default.

You must either serialize your complex type into save and then save into web part

OR

You must write the type converter for your complex type and specify that type converter in your web part as an attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号