# User Data

There are at least three ways to add custom properties (or user data) to controls in Wisej.NET:

1. Extend the class
2. Tag property
3. UserData property

Extending the class is the most flexible approach but in some cases it's not feasible to create a new class of a control just to add a value use in a small specific context.

The [Tag ](https://docs.wisej.com/api/wisej.web/general/control#tag)property is available at design time at provides a quick way to add custom information to an instance of a control.

The [UserData ](https://docs.wisej.com/api/wisej.web/general/control#userdata)property is a dynamic object that allows you to add any kind of fields to a control without having to create a new class.

## Extend the class

All Wisej.NET control classes can be used as the base class of your classes. You can create new types of buttons, tab pages, tree nodes, grid cells, grid rows, columns, forms, etc.

For example, if you need to have a [TreeNode ](https://docs.wisej.com/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode)instance that is associated with a Customer instance you can create a CustomerTreeNode class.

{% tabs %}
{% tab title="C#" %}

```csharp
class CustomerTreeNode : Wisej.Web.TreeNode
{
    public Customer Customer {get; set; }
}

...

this.treeView1.Nodes.Add(new CustomerTreeNode
{
    Customer = goodCustomer
});
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Class CustomerTreeNode
    Inherits Wisej.Web.TreeNode
    
    Public Property Customer
    
End Class

...

Me.TreeView1.Nodes.Add(New CustomerTreeNode With 
{
    .Customer = goodCustomer
    
```

{% endtab %}
{% endtabs %}

You can use the new *CustomerTreeNode* class just like the base TreeNode class, including at design time. When adding nodes at design time, the designer will show a drop down button to pick the specific TreeNode class to add.

## Tag Property

All controls and components in Wisej.NET expose the [Tag ](https://docs.wisej.com/api/wisej.web/general/control#tag)property of type object. You can "tag" any control or component with any value of any type.

## UserData property

The [UserData ](https://docs.wisej.com/api/wisej.web/general/control#userdata)property is similar to the Tag property except that it's a dynamic object that can hold any number of fields of any kind.

For example, we can "attach" a Customer instance to a TreeNode without creating a CustomerTreeNode class like this:

{% tabs %}
{% tab title="C#" %}

```csharp
var node = new TreeNode();
node.UserData.Customer = goodCustomer;
this.treeView1.Nodes.Add(node);

// Alternative using the property name.
var node = new TreeNode();
node.UserData["Customer"] = goodCustomer;
this.treeView1.Nodes.Add(node);
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
' this is necessary in VB.NET to use dynamic objects.
Option Strict Off

Dim node As New TreeNode();
node.UserData.Customer = goodCustomer
Me.TreeView1.Nodes.Add(node)

' with strict on use the propert name.
Option Strict On

Dim node As New TreeNode();
node.UserData("Customer") = goodCustomer
Me.TreeView1.Nodes.Add(node)
```

{% endtab %}
{% endtabs %}

As shown in the code snippet above, the UserData property is a dynamic object and a dictionary.

{% hint style="success" %}
To check whether an object has any data in the UserData dictionary without forcing the creation of the storage object, use the [HasUserData ](https://docs.wisej.com/api/wisej.web/general/control#hasuserdata)property.
{% endhint %}
