Last post Mar 27, 2008 04:34 PM by JByrd2007
Mar 25, 2008 02:06 PM|aggiekevin|LINK
How can I make a property in a custom control or web user control required, so that if that property is not set by the developer when using the control in a page, a compilation error occurs?
Mar 25, 2008 02:50 PM|jkirkerx|LINK
Why not just check if the property exist, and if not, write to the screen, you must set the property
If [CssClass] Is string.Empty Then
writer.Write("Set the Css")
Mar 25, 2008 06:56 PM|aggiekevin|LINK
Because I don't want to have to wait until run-time to figure out something was not configured properly.
Mar 27, 2008 04:34 PM|JByrd2007|LINK
You can use a preprocessor directive to trigger a compile-time error when a value is not defined for the property of the control.
In this case, I overrode the RenderContents method of the control and added a check of the property. This example will generate an error if you compile a page with the control if the value of the property (in this case a string) is null/empty:
(other code to render the control's output here)...
Hope this helps!