Custom properties for custom webpart in wss 3.0
May 18th, 2007 — ¥ong¥s
Free Link Exchange Software and Automate Link Swap Service
Offers free link swap service, link trade directory, reciprocal link exchange software that auto updates your link pages and complete link exchange. |
Writing custom properties for your own web part isn’t that complex. Here is a simple example to do that.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using System.Web.UI.WebControls.WebParts;
namespace SampleWebPart
{
[DefaultProperty("DisplayText"),
ToolboxData("<{0}:Sample runat=server></{0}:Sample>"),
XmlRoot(Namespace = "SampleWebPart")]
public class Sample : WebPart
{
private string displayText = “Hello World!”;
[WebBrowsable(true), Personalizable(true)]
public string DisplayText
{
get { return displayText; }
set { displayText = value; }
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write(displayText);
}
}
}