Conclusion
ASP.NET's Page infrastructure is set up so that each page is broken down into smaller components (server-side controls) that are responsible for rendering a small amount of HTML into the page's output stream. After reading this tutorial, you probably have a good idea as to how some of the standard ASP.NET controls work. Button controls render an input tag with a type of "submit." TextBox controls render an input tag with a type of "text." You can actually see how each of the controls in a page renders by viewing the HTML that comes back to the browser.
Of course, because ASP.NET's Page infrastructure is set up this way, it leaves the door open for custom User controls. In this tutorial we looked at rendered custom controls. Custom controls that render have the ability to squirt anything they want into the output bound for the browser. Custom rendered controls usually manage a set of properties, fire events to their hosts, and render snapshots of themselves to their hosts. In this tutorial we built a palindrome checker as an example. Next, we'll see examples of the other kind of custom control-composite-style controls.
Tutorial 4 Quick Reference
How to create a custom control that takes over the rendering process
Derive a class from
System.Web.UI.ControlOverride the Render method
Visual Studio includes a project type, Web Custom Control, that fits the bill
How to Add a custom control to the toolbox
Show the toolbox if it's not already showing by selecting
View | Toolboxfrom the main menuRight mouse click anywhere in the toolbox
Select Choose Items from the local menu
Choose a control from the list
OR
Browse to the assembly containing the control
How to Change the properties of controls on a page
Make sure the page editor is in Designer mode
Highlight the control whose property you want to change
Select the property to edit in the property window
How to Store view state information that lives beyond the scope of the page
Use the ViewState property of the control
It's a name/value dictionary that contains serializable types
Just be sure to use the same index to retrieve the information as you do to store the information
How to Write browser version-independent rendering code
Use the
HtmlTextWritertag-rendering methods for specific tags instead of hard-coding them. The Render method will have the correct HtmlTextWriter based on header information coming down from the browser.