1

If certain attributes on built-in ASP.NET controls aren't specified, then an exception will be thrown.

How do I do this on my custom user/server control?

crdx
  • 1,412
  • 13
  • 26

2 Answers2

1

One approach would be to ensure the getter on the property checks for an 'unset' state and throws an exception if that's found to be true.

Lazarus
  • 41,906
  • 4
  • 43
  • 54
0

Is there any specific reason why you want to throw an exception ?

The standard approach is to assign a default value if nothing is specified by the user. Another alternative is already mentioned above by Lazarus.

  • I want the user to have to explicitly provide the attribute. If I make it silently use a default, then its behaviour may be unpredictable from the user's perspective, and debugging will be more difficult. If they're forced to set it, then it's less prone to user error. – crdx Feb 24 '11 at 15:14