Developing Custom Properties for the Web Part
In NavigationWebPart.cs
, we’ll remove some additional code that has been added by the template before we create our properties. Remove all the generated comments and the following:
private const string defaultText = ""; private string text = defaultText; [Browsable(true), Category("Miscellaneous"), DefaultValue(defaultText), WebPartStorage(Storage.Personal), FriendlyName("Text"), Description("Text Property")] public string Text { get { return text; } set { text = value; } }
Also remove this auto-generated line from the RenderWebPart()
method:
Output.Write(SPEncode.HtmlEncode(Text));
Then add the import for the System.Web
namespace, and NavigationWebPart.cs
should now look like this:
using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint...