Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在自定义.NET Web控件中指定所需的属性?_C#_.net_Custom Controls - Fatal编程技术网

C# 如何在自定义.NET Web控件中指定所需的属性?

C# 如何在自定义.NET Web控件中指定所需的属性?,c#,.net,custom-controls,C#,.net,Custom Controls,当有人使用该控件时,我将如何使其成为必需的?我试图找到一个属性,该属性表示类似于Required(true)的内容。我不知道该属性是否存在。我相信在页面上的加载事件(或者某些渲染事件)只需检查值是否已设置。如果没有,则抛出异常。我认为这是不可能的。考虑到设计器需要在从工具箱拖动时创建控件的实例。此时,属性将具有默认值,并且这些值必须有效 private string _itemId; [Browsable(true), Description("Required identifier for

当有人使用该控件时,我将如何使其成为必需的?我试图找到一个属性,该属性表示类似于Required(true)的内容。

我不知道该属性是否存在。我相信在页面上的加载事件(或者某些渲染事件)只需检查值是否已设置。如果没有,则抛出异常。

我认为这是不可能的。考虑到设计器需要在从工具箱拖动时创建控件的实例。此时,属性将具有默认值,并且这些值必须有效

private string _itemId;

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