Scott on Writing

Musings on technical writing...

Creating Designers for Custom ASP.NET Server Controls

Over the past few months I have started building a number of custom ASP.NET server controls, something I had only before done once before.  What I am finding is that I'm really enjoying the process, in part, I think, because it is a “closer to the metal” programming paradigm than just regular ASP.NET Web application programming.  For those who aren't familiar, you can create your own custom Web controls with compiled code.  This can be useful for extending the functionality of an existing Web control, or building your own custom Web controls that aren't available with ASP.NET by default.  For example, in Easily Adding Functionality to ASP.NET Server Controls I look at how to extend the default Calendar Web control to use client-side script so that the day the mouse is hovering over is highlighted.  Some wonderful examples of (free) custom ASP.NET server controls can be found at MetaBuilders.com.

When creating server controls, you can also optionally build a Designer class.  The Designer class provides a rich GUI experience in the Visual Studio .NET designer.  If you use VS.NET then you are already familiar with the WYSIWYG Design tab - you can drag and drop a Web control, set its properties, and blam-o, the control's visual changes due to the property changes are automatically reflected in the designer.

Unfortunately, I haven't been able to find much online information on creating Designer classes.  Yes, there is G. Andrew Duthie's article Adding Design-Time Support to ASP.NET Controls, and there are assorted tidbits I've found on other sites, but nothing incredible comprehensive.  The best resource I've found thus far is Chapter 15 of Developing Microsoft ASP.NET Server Controls & Components.  (BTW, this book is a must have for anyone serious about ASP.NET server control development.)  I've also found it helpful to look at the Designer classes created by other individuals.

One thing that I didn't find out until today (which is neatly tucked away on the last page of Chapter 15 in the aforementioned book), is how to debug Designer classes.  If there is a bug in your Designer class, when someone drags and drops your custom server control from the Toolbox onto the Design tab, a little box will appear saying there is some error in displaying the control.  That's it!  No hint or clues as to what might be causing the problem.  Debugging the Designer class, however, is possible, with the following steps:

  1. In the Designer class Project, access the Project's Property dialog box by right-clicking on the Project name in the Solution Explorer and choosing Properties.
  2. Go to the Debugging settings in the Configurations Properties folder and choose the Debug Mode as Program.
  3. Set the Start Application as devenv.exe (you may need to include the path to the file - this is the Visual Studio .NET IDE EXE file...)
  4. Set a breakpoint in your Designer class at an appropriate location...
  5. Hit F5 to start debugging, this will open up another instance of VS.NET
  6. Create a new ASP.NET Web application and add to the References folder the assembly that contains the Designer class.
  7. Drag and drop your custom control from the Toolbox onto the Design tab - you should be taken to the breakpoint in your Designer class.

Also, if you find looking at others' Designer classes as a good education tool, I invite you to check out an open-source project I started up last month called skmMenu.  It's an ASP.NET menu control, with full source code available for free, including a Designer class.  You can find it on the GotDotNet Workspaces.  Also there will (eventually) be two articles about skmMenu up on the MSDN ASP.NET Dev Center.

posted on Wednesday, October 15, 2003 3:36 PM

Feedback

No comments posted yet
Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<July 2008>
SMTWTFS
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Comment Stats

DayTotal% of Total
Sunday 1896.8%
Monday 39014.0%
Tuesday 46916.8%
Wednesday 51518.5%
Thursday 54419.5%
Friday 50818.2%
Saturday 1706.1%
Total 2785100.0%

Hour1Total% of Total
12:00 AM 682.4%
1:00 AM 712.5%
2:00 AM 632.3%
3:00 AM 752.7%
4:00 AM 572.0%
5:00 AM 1093.9%
6:00 AM 1114.0%
7:00 AM 1615.8%
8:00 AM 1756.3%
9:00 AM 1505.4%
10:00 AM 1736.2%
11:00 AM 1826.5%
12:00 PM 1906.8%
1:00 PM 1766.3%
2:00 PM 1605.7%
3:00 PM 1324.7%
4:00 PM 1124.0%
5:00 PM 983.5%
6:00 PM 913.3%
7:00 PM 993.6%
8:00 PM 853.1%
9:00 PM 802.9%
10:00 PM 833.0%
11:00 PM 843.0%
Total 2785100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.14144
Monday 5.35353
Tuesday 4.35444
Wednesday 7.58644
Thursday 6.87625
Friday 5.45414
Saturday 5.03161
Total 5.802785

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.45109
9:00 AM 6.34279
10:00 AM 6.41250
11:00 AM 4.28184
12:00 PM 6.98342
1:00 PM 2.87112
2:00 PM 5.29222
3:00 PM 8.54299
4:00 PM 3.9190
5:00 PM 5.78156
6:00 PM 4.52113
7:00 PM 9.32177
8:00 PM 9.06154
9:00 PM 5.14113
10:00 PM 6.2381
11:00 PM 4.5732
Total 5.802785

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles