必须按要求ASP.NET服务器控件属性属性 [英] ASP.NET Server Control Property Attribute must be required
问题描述
我有一个自定义ASP.NET服务器控件 CustomControl
与属性的属性路径
。
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.
例如,
< myControls:CustomControl PATH =somedirectory / someotherdirectory / somefile.ext=服务器/>
应该编译,以及
< myControls:CustomControl =服务器/>
应该抛出一个异常
我知道我可以在路径
属性的getter做到这一点,但那里,就必须这样一些特性?
I realize I can do this in the getter of the Path
property, but is there some attribute that necessitates this?
有没有验证属性值的任何属性的机制比使用在$ C $的getter方法C-背后性质的其他?
Is there any mechanism for validating the values of the property attributes other than using in the getter methods of the code-behind properties?
推荐答案
您可以在自定义控件的Init事件检查,并抛出一个异常。
You can check this in init event of the custom control, and throw an exception.
更新
有;检查在init事件。作为控制主机的(页面或用户控件)init事件后调用初始化的。所以,你可以,如果抛出一个异常,其空或空
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
这篇关于必须按要求ASP.NET服务器控件属性属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!