# Javascript: SubTextPart.getName Method

> Relates a user-defined name to a subtextpart.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: SubTextPart.getName Method
- **414 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpart/getname-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpart/getname-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpart/getname-method/llms-full.txt

---

### Description

Relates a user-defined name to a subtextpart.

### Syntax

```javascript
<void> SubTextPart.getName(<RequestStringCallback> callback, [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| callback | Receives the name. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `SubTextPart.getName` in a practical document-editing workflow. Relates a user-defined name to a subtextpart.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const subTextParts = mainText.subTextParts;
    subTextParts.getItem(function(subTextPart) {
        if (!subTextPart) {
            console.warn("No sub text part is available at the current input position.");
            return;
        }
    
        subTextPart.getName(
            function(result) {
                console.log("get name result:", result);
            },
            onTxError
        );
    }, onTxError);
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: SubTextPart.getLength Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpart/getlength-method/llms-full.txt)
- **Next:** [Javascript: SubTextPart.getNestedLevel Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/subtextpart/getnestedlevel-method/llms-full.txt)
