Conclusion: How standard ASP.Net controls work

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

  1. Derive a class from System.Web.UI.Control

  2. Override the Render method

  3. Visual Studio includes a project type, Web Custom Control, that fits the bill

How to Add a custom control to the toolbox

  1. Show the toolbox if it's not already showing by selecting View | Toolbox from the main menu

  2. Right mouse click anywhere in the toolbox

  3. Select Choose Items from the local menu

  4. Choose a control from the list


  5. Browse to the assembly containing the control

How to Change the properties of controls on a page

  1. Make sure the page editor is in Designer mode

  2. Highlight the control whose property you want to change

  3. Select the property to edit in the property window

How to Store view state information that lives beyond the scope of the page

  1. Use the ViewState property of the control

  2. It's a name/value dictionary that contains serializable types

  3. 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 HtmlTextWriter tag-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.