Dear All
I'm just getting started with writing web parts for a SharePoint environment. I would like to be able to have a couple custom properties in my web part that can be customised, not per user (i.e. personalisation) but for the shared page.
Here is the code that I'm working with. The first property that I've used appears in the web part properties pane. The second property doesn't work -- I think the only difference is I've tried to put it into a category and make it Storage.Shared. The web part compiles fine without errors or warnings and deploys to my SharePoint site. However, only the first property appears -- the second is no-where to be seen.
Option Explicit On
Option Strict On
Imports System
Imports System.Runtime.InteropServices
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.WebPartPages
Imports System.ComponentModel
Namespace ExamResults
<Guid("a2dca7a1-e9b4-42a6-b888-86b143523ee3")> _
Public Class WebPart1
Inherits System.Web.UI.WebControls.WebParts.WebPart
Private _start As String = [String].Empty
' Private variables
Private _myString As String
Public Sub New()
Me.Title = "Virtual Earth Driving Directions Web Part"
Me.ExportMode = WebPartExportMode.All
' Initialize private variables.
_myString = "Hello"
End Sub
' Property to personalize the start location
<Personalizable()> _
<WebBrowsable()> _
Public Property Start() As String
Get
Return _start
End Get
Set(ByVal value As String)
_start = value
End Set
End Property
' This one doesn't work
<Category("Custom Properties")> _
<DefaultValue("Hello")> _
<WebPartStorage(Storage.Shared)> _
<FriendlyNameAttribute("Percentage")> _
<Description("Enter a percentage.")> _
<Browsable(True)> _
<XmlElement(ElementName:="MyString")> _
Public Property MyString() As String
Get
Return _myString
End Get
Set(ByVal value As String)
_myString = value
End Set
End Property
' Render a Virtual Earth Map as a Web part
Protected Overloads Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
If [String].IsNullOrEmpty(_start) Then
writer.Write("Select a start point by personalizing this WebPart.")
Else
MyBase.RenderContents(writer)
writer.Write([String].Format(HtmlFormat, _start))
End If
End Sub
End Class
End Namespace
Please could you help me to get started with this?
Many thanks
Daniel