ASP.NET Server Control Property Attribute must be required

橙三吉。 提交于 2019-11-29 11:25:49

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.

There is not an attribute that necessitates this. The best place to do this is in the getter of the Path property.

No, there's no way to force the page framework to do this. You need to do it in your code at runtime and raise an exception if the value wasn't provided. Otherwise we'd never run into the "crap, I forgot the runat=server part" error :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!