Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 259217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:14:44+00:00 2026-05-11T22:14:44+00:00

I have used the following article as a guide to creating a custom EditorPart

  • 0

I have used the following article as a guide to creating a custom EditorPart in SharePoint

http://blah.winsmarts.com/2006/05/19/writing-custom-editors-for-sharepoint-2007-and-aspnet-20-webparts.aspx

However when I implement this technique I cannot save the changes to my custom properties. Basically the CreateChildControls function is called when the ‘Apply’ or ‘Save’ buttons are used and this creates a new instance of my internal control variable, thus wiping any changes the user has made.

So when the ApplyChanges function is called all the controls are back to the default settings.

Does anyone have any advice on this?

Thanks

UPDATE

I am just not able to wrap my head around this at all. However I look at this I get stuck at the same point, how can I save anything back to my web part in ApplyChanges() when CreateChildCOntrols() is always run first thus replacing my CheckBoxList with a new instance and therefore no selected items. I have included the full code below in the hope that I am being a total dunce and the solution is obvious.

Private Class CaseMatterInfoEditorPart
    Inherits EditorPart

    Protected WithEvents _propList As CheckBoxList

    Protected Overrides Sub CreateChildControls()

        _propList = New CheckBoxList
        _propList.EnableViewState = True
        _propList.AutoPostBack = True
        _propList.Width = New Unit("100%")

        LoadProperties()

        Me.Controls.Add(New LiteralControl("Please select the data items you wish to include:<br />"))
        Me.Controls.Add(_propList)

    End Sub


    Public Overrides Function ApplyChanges() As Boolean

        Dim part As CaseMatterInfoPart = CType(WebPartToEdit,  _
                                               CaseMatterInfoPart)

        If part IsNot Nothing Then
            GetSelectedDataValues()
        Else
            Return False
        End If

        Return True

    End Function

    Public Overrides Sub SyncChanges()

        EnsureChildControls()

        Dim part As CaseMatterInfoPart = CType(WebPartToEdit,  _
                                               CaseMatterInfoPart)

        If part IsNot Nothing Then

            If Not String.IsNullOrEmpty(part.DataValues) Then
                SetSelectedValues(part.DataValues)
            End If

        End If


    End Sub

    Private Function GetSelectedDataValues() As String

        Dim strReturn As String = ""

        For Each item As ListItem In _propList.Items

            If item.Selected Then
                strReturn &= item.Text & "|"
            End If

        Next

        If Not String.IsNullOrEmpty(strReturn) Then
            strReturn = strReturn.Remove(strReturn.Length - 1, 1)
        End If

        Return strReturn

    End Function

    Private Sub SetSelectedValues(ByVal Values As String)

        If Not String.IsNullOrEmpty(Values) And _
            _propList IsNot Nothing Then

            _propList.ClearSelection()

            Dim split() As String = Values.Split("|")

            For Each strValue As String In split

                For Each item As ListItem In _propList.Items

                    If item.Text = strValue Then
                        item.Selected = True
                    End If

                Next

            Next

        End If

    End Sub

    Private Sub LoadProperties()

        Dim file As New File
        Dim lstProperties As List(Of String) = GetStringPropertyNames(file.GetType)

        For Each strProperty As String In lstProperties

            _propList.Items.Add(strProperty)

        Next

    End Sub

    Private Function GetStringPropertyNames(ByVal Type As System.Type) As List(Of String)

        Dim props() As PropertyInfo = Type.GetProperties
        Dim propList As New List(Of String)

        For Each prop As PropertyInfo In props

            If prop.Name <> "Chronology" And _
                    prop.Name <> "Documents" And _
                    prop.Name <> "Milestones" And _
                    prop.Name <> "DiaryEntries" And _
                    prop.Name <> "FileLoadSuccesful" And _
                    prop.Name <> "FileLoadError" Then

                Dim boo As Boolean = False
                Dim bootype As Type = boo.GetType
                Dim dec As Decimal
                Dim decType As Type = dec.GetType

                If prop.PropertyType Is "".GetType Or _
                    prop.PropertyType Is Now.GetType Or _
                    prop.PropertyType Is bootype Or _
                    prop.PropertyType Is decType Then

                    propList.Add(prop.Name)

                Else

                    Dim listChildPropertyStrings As List(Of String) = GetStringPropertyNames(prop.PropertyType)

                    For Each strProp As String In listChildPropertyStrings

                        propList.Add(prop.Name & ": " & strProp)

                    Next

                End If

            End If


        Next

        Return propList

    End Function

End Class

Hope someone out there can see what I cannot.

Thanks

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:14:44+00:00Added an answer on May 11, 2026 at 10:14 pm

    It would help if I had actually saved the string returned from GetSelectedDataValues() into a property on the web part…

    Actual code should look like this:

    Public Overrides Function ApplyChanges() As Boolean        
        Dim part As CaseMatterInfoPart = CType(WebPartToEdit, CaseMatterInfoPart)        
        If part IsNot Nothing Then            
            part.DataValues = GetSelectedDataValues()        
        Else            
            Return False        
        End If        
        Return True    
    End Function
    

    It so often pays to check, double check and triple check what you are doing. I had serioulsy over complicated this issue looking for an answer that was staring me in the face.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following string: cn=abcd,cn=groups,dc=domain,dc=com Can a regular expression be used here to
I have used the code supplied in the following CodeProject article in the past
I found the following rather strange. Then again, I have mostly used closures in
I have the following code in an Autofac Module that is used in my
From the iPhone Programming Guide When creating files or writing out file data, keep
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have used the XML Parser before, and even though it worked OK, I
I have used Photoshop CS2's Save for Web feature to create a table of
I have used this in my HTML: <q> Hai How r u </q> Which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.