I have a custom ASP.NET server control CustomControl
with a property attribute Path
.
If the Path
is not explicitly specified, then I want an exception to be thrown.
For example,
<myControls:CustomControl Path="somedirectory/someotherdirectory/somefile.ext" runat="server" />
should compile, and
<myControls:CustomControl runat="server" />
should throw an exception.
I realize I can do this in the getter of the Path
property, but is there some attribute that necessitates this?
Is there any mechanism for validating the values of the property attributes other than using in the getter methods of the code-behind properties?
You can check this in init event of the custom control, and throw an exception.
Update
There is; Check it in init event. As init of control's called after host's (page or user control) init event. So you can throw an exception if its null or empty
I don't think this should be a compile time check.
After all, the property value might be supplied in the code behind during page_load or a similiar event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With