# Getting Started with the SmartPasteButton

This guide demonstrates how to set up the Telerik UI for ASP.NET Core SmartPasteButton and use it to populate form fields based on clipboard text.

For a complete example, refer to the [SmartPasteButton demo](https://demos.telerik.com/aspnet-core/smartpastebutton).

## 1. Add the Target Editors

The following example shows the editors that will receive the extracted values.

```Razor HtmlHelper
<form id="form-getting-started">
    @(Html.Kendo().TextBox()
        .Name("fullName")
        .Label(l => l.Content("Full Name"))
        .Placeholder("Full Name")
    )

    @(Html.Kendo().TextBox()
        .Name("city")
        .Label(l => l.Content("City"))
        .Placeholder("City")
    )

    @(Html.Kendo().MaskedTextBox()
        .Name("phone_number")
        .Label(l => l.Content("Phone Number"))
        .HtmlAttributes(new { placeholder = "e.g. XXXXXXXX" })
        .Mask("(000) 000-00-00")
    )
</form>
```

```Razor TagHelper
@addTagHelper *, Kendo.Mvc

<form id="form-getting-started">
    <kendo-textbox name="fullName" placeholder="Full Name">
        <textbox-label content="Full Name" />
    </kendo-textbox>

    <kendo-textbox name="city" placeholder="City">
        <textbox-label content="City" />
    </kendo-textbox>

    <kendo-maskedtextbox name="phone_number"
                         mask="(000) 000-00-00"
                         placeholder="e.g. XXXXXXXX">
        <maskedtextbox-label content="Phone Number" />
    </kendo-maskedtextbox>
</form>
```

## 2. Add the SmartPasteButton

Use the `Service()` configuration to point the component to your AI SmartPaste service.

```Razor HtmlHelper
@(Html.Kendo().SmartPasteButton()
    .Name("smartPaste")
    .Service("https://demos.telerik.com/service/v2/ai/smartpaste/smartpaste")
    .Text("Smart Paste")
    .Events(e => e.RequestStart("onRequestStart").RequestEnd("onRequestEnd"))
)
```

```Razor TagHelper
@addTagHelper *, Kendo.Mvc

<kendo-smartpastebutton name="smartPaste"
                        text="Smart Paste"
                        on-request-start="onRequestStart"
                        on-request-end="onRequestEnd">
    <service url="https://demos.telerik.com/service/v2/ai/smartpaste/smartpaste" />
</kendo-smartpastebutton>
```

## 3. Handle the Request Lifecycle

In the demo, the `RequestStart` and `RequestEnd` handlers show and hide a Loader.

```JS Scripts
<script>
    function onRequestStart() {
        var loader = $("#loader").data("kendoLoader");
        loader.show();

        $("#copyButton").find(".k-button-text").text("Copy Text");
        clearSelection();
    }

    function onRequestEnd() {
        var loader = $("#loader").data("kendoLoader");
        loader.hide();
        $("input").addClass("k-valid");
    }

    function clearSelection(){
        var selection = window.getSelection();

        if (selection && selection.rangeCount > 0) {
            selection.removeAllRanges();
        }
    }
</script>
```

## See Also

* [SmartPasteButton Overview](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/smartpastebutton/overview)

* [Events of the SmartPasteButton](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/smartpastebutton/events)

* [AI Service Integration](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/smartpastebutton/ai-service-integration)

* [Server-Side API of the SmartPasteButton ](https://www.telerik.com/aspnet-core-ui/documentation/api/smartpastebutton)

* [Server-Side API of the SmartPasteButton TagHelper](https://www.telerik.com/aspnet-core-ui/documentation/api/taghelpers/smartpastebutton)

* [Knowledge Base Section](https://www.telerik.com/aspnet-core-ui/documentation/knowledge-base)
