ASP.NET Server Property Attribute Must Be Required

I have a custom ASP.NET server control CustomControlwith a property attribute Path.

If the value Pathis not explicitly specified, I want the exception to be thrown.

For instance,

<myControls:CustomControl Path="somedirectory/someotherdirectory/somefile.ext" runat="server" />

should compile and

<myControls:CustomControl runat="server" /> should throw an exception.

I understand that I can do this in the getter property Path, but is there any attribute that requires this?

Update

Is there any mechanism for checking property attribute values ​​other than using code properties in getter methods?

+3
source share
4 answers

init .

; init. init init ( ) init. , ,

+6

, . - getter Path.

0

I do not think this should be a compile-time check.

In the end, the property value can be provided in the code behind during page_load or a similar event.

0
source

No, there is no way to force the page structure to do this. You need to do this in your code at runtime and throw an exception if this value was not provided. Otherwise, we will never encounter the error "crap, I forgot the error runat = server" :)

0
source

All Articles