Wednesday, November 28, 2007

Creating a Web Part with Custom Properties

Thee Web Part we talk about here derived from System.Web.UI.WebControls.WebParts.

using System;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
 
namespace LitwareWebPartsLab2
{
 public class RevenueWebPart:WebPart
 {
 private bool _myBool = false;
 
 protected override void RenderContents(HtmlTextWriter writer)
 {
 if (_myBool)
 writer.Write("<B>Hello, world</B>");
 else
 writer.Write("Hello, world");
 }
 
 [Personalizable(PersonalizationScope.Shared),
 WebBrowsable(true),
 System.ComponentModel.Category("Miscellaneous"),
 WebDisplayName("Show Text As Bold"),
 WebDescription("Show Text As Bold.")]
 // The accessor for this property.
 
 public bool showTextAsBold
 {
 get
 {
 return _myBool;
 }
 set
 {
 _myBool = value;
 }
 }
 }
}