如何指定一个自定义的.NET Web控件所需的属性? [英] How do I specify a required attribute in a custom .NET Web control?

查看:167
本文介绍了如何指定一个自定义的.NET Web控件所需的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private string _itemId;

[Browsable(true),
Description("Required identifier for the Item.")]
public string ItemId
{
    get { return _itemId; }
    set
    {
    	if (string.IsNullOrEmpty(_itemId))
    	{
    		_itemId = value;
    	}
    }
}

如何将我居然提出,当有人使用的控制?我试图找到一个属性,它说像必需(真)。

How would I actually make that required when someone uses the control? I'm trying to find an attribute that says something like Required(true).

推荐答案

我不知道,有此属性。我相信,在Page_Load事件(或者一些渲染事件)只检查是否值已设置。如果没有,那么抛出异常。

I don't know that there's an attribute for this. I believe on the Page_Load event (or perhaps some rendering event) just check if the value has been set. If not then throw an exception.

这篇关于如何指定一个自定义的.NET Web控件所需的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆