# Copy Text from TextBox to Clipboard

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC TextBox</td> 
 </tr>
 <tr>
  <td>Product Version</td>
  <td>2024.1.130</td>
 </tr>
</table>

## Description

How can I copy text from the TextBox component directly within the Clipboard?

## Solution

To achieve the desired result:

1. Utilize the TextBox's [`SuffixOptions()`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/textboxbuilder#suffixoptionssystemaction) configuration and define a template.
2. Within the template, create a Button component and wire to its [`Click`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/buttonbuilder#eventssystemaction) event.
3. Within the event handler, use the [Clipboard](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) interface's [`writeText()`](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText) method to copy the text from the TextBox.

```Razor Index.cshtml
     @(Html.Kendo().TextBox()
        .Name("email")
        .Label(l => l.Content("Email Address").Floating(false))
        .Value("test@mail.com")
        .SuffixOptions(suffix => suffix
             .Template(Html.Kendo().Template()
                .AddComponent(component => component
                    .Button()
                    .Name("copyBtn")
                    .Icon("copy")
                    .Events(events => events.Click("onClick"))
                )
             )

        )
        .HtmlAttributes(new { style = "width: 100%;", type = "email" })
    )
```

```JS script.js
    <script>
        function onClick(e){
            var textBoxValue = $("#email").getKendoTextBox().value();
            navigator.clipboard.writeText(textBoxValue);
        }
    </script>    
```

To see an extended example of the aforementioned approach, refer to the [REPL example on copying text from the TextBox within the Clipboard](https://netcorerepl.telerik.com/woaxlyFM36koF7hy56).

## More ASP.NET MVC TextBox Resources

* [ASP.NET MVC TextBox Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/textbox/overview)

* [ASP.NET MVC TextBox Demos](https://demos.telerik.com/aspnet-mvc/textbox/index)

* [ASP.NET MVC TextBox Product Page](https://www.telerik.com/aspnet-mvc/textbox)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Telerik REPL (HtmlHelper): Copy Text from TextBox to Clipboard ](https://netcorerepl.telerik.com/woaxlyFM36koF7hy56)

* [Client-Side API Reference of the TextBox for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/textbox)

* [Server-Side API Reference of the TextBox for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/textbox)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
