SharePoint Development Bookmark and Share   
 index > SharePoint - Development and Programming > Save web part settings
 

Save web part settings

        <Personalizable(), WebBrowsable(True), DefaultValue(""), WebPartStorage(Storage.Personal), FriendlyName("Description"), Description("")> _

        Public Property pClassDescription() As String

            Get

                Return _pclassDescription

            End Get

            Set(ByVal value As String)

                _pclassDescription = value

            End Set

        End Property

I am making a web part where in design mode the web part shows a bunch of controls for editing the web part.

When I hit a save button and save to the properties they do not persist across post back. If I set the properties up to be seen in the web part editor panel they persist.

Is there some update command I need to run in the buttons on click event or some attribute I need to give my properties?
GreenWaterBoy  Friday, September 25, 2009 3:17 PM
The problem you will have is setting these properties, its very long winded if they aren't in the editor part. You will need to get the current SPFile, get the SPLimitedWebPartManager, retrieve the webpart from the collection, set properties and save.
My SharePoint Blog - http://www.davehunter.co.uk/blog
Dave Hunter  Friday, September 25, 2009 3:53 PM
Are you using a custom EditorPart? If so you need to call ApplyChanges() and SyncChanges().

My SharePoint Blog - http://www.davehunter.co.uk/blog
Dave Hunter  Friday, September 25, 2009 3:27 PM
Here's an article walking you through creating custom editor parts http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?ID=36

Hope this helps

Dave

My SharePoint Blog - http://www.davehunter.co.uk/blog
Dave Hunter  Friday, September 25, 2009 3:29 PM
Im not using a custom editorpart, i think.

The controls are in the webpart, they just only show up in DesignDisplayMode.

There is alot questions that need to be answered, including a large rich text box. So id rather have the controls in the main web part instead of in the editor bar. Similar to when you edit a content editor web part or something like that.

GreenWaterBoy  Friday, September 25, 2009 3:40 PM
The problem you will have is setting these properties, its very long winded if they aren't in the editor part. You will need to get the current SPFile, get the SPLimitedWebPartManager, retrieve the webpart from the collection, set properties and save.
My SharePoint Blog - http://www.davehunter.co.uk/blog
Dave Hunter  Friday, September 25, 2009 3:53 PM
Thanks i found some code for doing the long winded way http://stackoverflow.com/questions/485527/how-to-programmatically-update-content-in-a-sharepoint-web-part
GreenWaterBoy  Friday, September 25, 2009 4:57 PM
Ok I have this code so far.

Im trying to access the property, I see I can get at the title of the webpart. How do I access my custom properties?

I tried wp("propertyname"), that didnt work. I didnt see anything in the web parts object indicating how to get at it.

            Dim site As SPSite = SPContext.Current.Site
            Dim web As SPWeb = SPContext.Current.Web
            Dim file As SPFile = SPContext.Current.File
            Dim webMan As SPLimitedWebPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared)
            Dim wp As WebParts.WebPart = webMan.WebParts(Me.ID)
GreenWaterBoy  Friday, September 25, 2009 5:26 PM
Cast the webpart object to your custom webpart class:

Dim myPart = CType(wp, <your webpart type>)
myPart.PropertyName = "some value";
Pablo Gazmuri  Friday, September 25, 2009 5:38 PM
Man I kinda feel stupid for not figuring that out lol. Thanks.
GreenWaterBoy  Friday, September 25, 2009 5:39 PM
Any idea why GetLimitedWebPartManager is returning null? I tried using it as web.GetlimitedWebpartManager and file.GetLimitedWebpartManger and both method return nothing.

I debugged it and file is the correct file and was not null.

Dim site As SPSite = SPContext.Current.Site
Dim web As SPWeb = SPContext.Current.Web

Dim file As SPFile = SPContext.Current.File
Dim webMan As SPLimitedWebPartManager = web.GetLimitedWebPartManager(SPContext.Current.File.Url, PersonalizationScope.Shared)
Dim wp As WebParts.WebPart = webMan.WebParts(Me.UniqueID)
Dim Wep As WebPart12 = CType(wp, WebPart12)
GreenWaterBoy  Friday, September 25, 2009 7:16 PM
Nevermind I got it.

It looks like you cant use SPContext.Current.Site if you want to use GetLimitedWebPartManager

In case anyone is interested here is the working code.

            Using site As SPSite = New SPSite("http://weburl/site")
                Using web As SPWeb = site.OpenWeb
                    Dim file As SPFile = SPContext.Current.File

                    Using webMan As SPLimitedWebPartManager = web.GetLimitedWebPartManager(SPContext.Current.File.Url, PersonalizationScope.Shared)
                        Dim wp As WebParts.WebPart = webMan.WebParts(Me.ID)
                        Dim Wep As WebPart12 = CType(wp, WebPart12)
                        Wep.pClassTitle = ClassTitle.Text
                        webMan.SaveChanges(wp)
                    End Using

                    file.Update()

                End Using
            End Using
  • Edited byGreenWaterBoy Friday, September 25, 2009 8:06 PMremoved unneeded code
  •  
GreenWaterBoy  Friday, September 25, 2009 7:47 PM

You can use google to search for other answers

Custom Search

More Threads

• How can I use an SQL query for a list lookup column?
• error replacing lookup field
• Can the default NewItem ListForm navigate to a custom page on the "ok" button click?
• Is it possible to access my sharepoint server using the method in this article?
• ICellConsumer for more than one property
• Custom Lookup Field In Sharepoint
• Permissions: allowing anyone to view document listing, but only users with proper permissions to open
• Confirmation Box in Web Part
• How to deploy lookup fields in a feature
• How to change the credentials while making web service call for SharePoint