Listing 2: C# • Modify the Template Code

I recommend modifying the WebPart Visual Studio 2005 template code as shown. Specifically, you should override the CreateChildControls method with (commented) code to create a Label that can be used immediately, as well as an example property, also commented and ready to use. This code is a close approximation to a "real world" WebPart used by developers.

public class $safeprojectname$ : 

public class Web_Part1 : 
	//Private Label lblLabel;

	// TODO: Define properties here.
	//private const string _defaultText = 
		//"One Property";
	//private string _myProperty = _defaultText;
	//WebDisplayName("One Property"),
	//WebDescription("Defines One Property"),
	//public string myProperty
	//  get { return _myProperty; }
	//  set { _myProperty = value; }

	protected override void Render(
		HtmlTextWriter writer)
	// TODO: Add custom rendering code here.
	// writer.Write("Output HTML");

	protected override void CreateChildControls()
	// TODO: Add custom CreateChildControls code here.
		//lblLabel = new Label();
		//lblLabel.Text = "my Label";
comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.